I have a string with a date in it formatted like so: YYYYMMDDHHMMSS. I was wondering how I would convert it into a JavaScript Date object with JavaScript.
Thanks in
There is no time zone information in your string. It most likely is GMT, so that should be accounted for when you make the Date. You can easily do the conversion with simple javascript methods.
Date.Brit= (function(){
return Date.parse('2/6/2009')> Date.parse('6/2/2009');
})()
var s= "20091202093000"
var D= s.match(/(\d{2})/g);
if(Date.Brit){
D.splice(2, 2, D[3],D[2]);
}
var day= new Date(Date.parse(D[2]+'/'+D[3]+'/'+
D[0]+D[1]+' '+D.splice(4).join(':')+' GMT'));
day.toUTCString()+'\n'+day
/* returned value: (String)
Wed, 02 Dec 2009 09:30:00 GMT
Wed Dec 02 2009 04:30:00 GMT-0500 (Eastern Standard Time)
*/