javascript - Parse custom Date from string -


possible duplicate:
help parsing iso 8601 date in javascript

i have set of strings, in similar form: 2012-05-31t00:00:00.0000000

all want pull year (2012), month (05), , day (31), construct javascript date object data.

what best way parse data?

the easiest way can think of using regular expression, , passing values date constructor:

function parseisodate(datestring) {     var match = /^(\d{4})-(\d\d)-(\d\d)/.exec(datestring);     return new date(number(match[1]), number(match[2]) - 1, number(match[3])); }  console.log(parseisodate('2012-05-31t00:00:00.0000000')); // date {thu may 31 2012 00:00:00 gmt+0200} 

of course, expand match time well...


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -