I have a map.I am converting the Map into a JSON Object.I am reading the JSON object and want to convert it into a Javascript date.
The Date object I send is read as 2012-12-19T06:00:00.000+0000 in js and I do not understand what is the T in this String.Anyone can throw light on this
I have a map.I am converting the Map into a JSON Object.I am reading the JSON object and want to convert it into a Javascript date.
The Date object I send is read as 2012-12-19T06:00:00.000+0000 in js and I do not understand what is the T in this String.Anyone can throw light on this
Share Improve this question asked Jan 15, 2013 at 3:56 HarishHarish 3,48315 gold badges56 silver badges75 bronze badges 3- t for timezone I guess, use datejs – Jonathan de M. Commented Jan 15, 2013 at 3:59
-
the time format is ISO-8601.
T
is time delimiter, read more at: en.wikipedia/wiki/ISO_8601 ( section: Combined date and time representations ) – Raptor Commented Jan 15, 2013 at 4:00 - Modern browsers will parse the string correctly if you change the offset (+0000) to +00:00(Though if it is always 0 offset, use 'Z' instead. – kennebec Commented Jan 15, 2013 at 4:31
3 Answers
Reset to default 7It is a string representation of a date as per the ISO 8601 specification. Here T
stands for the beginning of the time portion of the datetime representation.
You can convert this representation to javascript date object using new Date('2012-12-19T06:00:00.000+0000')
.
You can use a regex to get only the date portion. The regex /\d{4}-\d{2}-\d{2}/.exec('2012-12-19T06:00:00.000+0000')[0]
will give you the date portion alone.
Refer ISO 8601
The "T" is part of the ISO 8601 serialisation of the date, which is the JavaScript Date String Format.
in java format the date to string the following simple date formatter
SimpleDateFormat formatter = new SimpleDateFormat("EE MMM d y H:m:s ZZZ");
String dateString = formatter.format(new Date());
In java script side use
new Date(dateString)