2

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

3
  • t for timezone I guess, use datejs Commented Jan 15, 2013 at 3:59
  • the time format is ISO-8601. T is time delimiter, read more at: en.wikipedia.org/wiki/ISO_8601 ( section: Combined date and time representations ) 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. Commented Jan 15, 2013 at 4:31

3 Answers 3

7

It 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

Sign up to request clarification or add additional context in comments.

3 Comments

how to get the Date alone ?
@Harish: What do you have if not the Date, do you have a string? Please show us your code
I got the solution.YYYY-MM-DDTHH:mm:ss.sssZ
4

The "T" is part of the ISO 8601 serialisation of the date, which is the JavaScript Date String Format.

Comments

2

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) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.