Why can't I create a Date from a string including milliseconds?

Posted by KooiInc on Stack Overflow See other posts from Stack Overflow or by KooiInc
Published on 2010-04-10T12:07:52Z Indexed on 2010/04/10 12:13 UTC
Read the original article Hit count: 278

Filed under:
|

In javascript you can create a Date object from a string, like

var mydate = new Date('2008/05/10 12:08:20');
console.log(mydate); //=> Sat May 10 2008 12:08:20 GMT+0200

Now try this using milliseconds in the string

var mydate = new Date('2008/05/10 12:08:20:551'); // or '2008/05/10 12:08:20.551'
console.log(mydate); //=> NaN

Just out of curiosity: why is this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about datetime