Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Date as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

I need to format a date as yyyy-MM-dd'T'HH:mm:ss.SSS'Z' as specified by Parse's REST API for Facebook. I was wondering what the most lightweight solution to this would be.

like image 232
Garrett Avatar asked Oct 17 '12 23:10

Garrett


People also ask

What does YYYY MM DD HH SS SSSZ mean?

Date formatting Dates are formatted using the following format: "yyyy-MM-dd'T'hh:mm:ss'Z'" if in UTC or "yyyy-MM-dd'T'hh:mm:ss[+|-]hh:mm" otherwise. On the contrary to the time zone, by default the number of milliseconds is not displayed.

What date format has T and Z?

ISO 8601. This format is defined by the sensible practical standard, ISO 8601. The T separates the date portion from the time-of-day portion. The Z on the end means UTC (that is, an offset-from-UTC of zero hours-minutes-seconds).

What is HH date format?

The hour, using a 12-hour clock from 01 to 12. More information: The "hh" Custom Format Specifier. The hour, using a 24-hour clock from 0 to 23. More information: The "H" Custom Format Specifier.


1 Answers

Call the toISOString() method:

var dt = new Date("30 July 2010 15:05 UTC"); document.write(dt.toISOString());  // Output: //  2010-07-30T15:05:00.000Z 
like image 157
Robert Harvey Avatar answered Sep 23 '22 08:09

Robert Harvey