datetime - JavaScript date parsing producing wrong date -


i have script:

var a="thu oct 07 16:50:0 cest 2010"; var b=a.split("cest"); var d = new date(b[0]); alert(d);​​​​​​​​​​​ 

but doesn't work how want. in fact date result differs original in string.

the input thu oct 07 16:50:0 cest 2010 result different sat oct 07 2000 16:50:00 gmt+0200 (cest). wrong?

you're losing information year. split splits string array @ 'cest' of parse first element (the part of string left of 'cest'). either need add right part of string again or use better suited method replace:

var a="thu oct 07 16:50:0 cest 2010"; var b=a.split("cest"); var d = new date(b[0]+b[1]); alert(d);​​​​​​​​​​​  var a="thu oct 07 16:50:0 cest 2010"; var b= a.replace('cest',''); var d = new date(b); alert(d);​​​​​​​​​​​ 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -