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

Garrett picture Garrett · Oct 18, 2012 · Viewed 115.4k times · Source

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.

Answer

Robert Harvey picture Robert Harvey · Oct 18, 2012

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