-3

How can I generate a date/time with JavaScript in this format:

2015-12-23T15:17:52.000Z
  • 3
    Possible duplicate of [Where can I find documentation on formatting a date in JavaScript?](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – user513951 Dec 23 '15 at 15:49
  • 2
    `new Date().toISOString()` – dandavis Dec 23 '15 at 15:50
  • It's not clear to me what you are asking for. Do you want to format a given date value in the above format? Or do you want to convert such a string to a date value? It's not a shame if your question contains more than just one sentence. – Felix Kling Dec 23 '15 at 15:50
  • This has already been solved many times over... look into http://momentjs.com/docs/ – An0nC0d3r Dec 23 '15 at 15:50
  • Hi, new Date().toISOString() is what I was looking for thanks dan – ProfessorManhattan Dec 23 '15 at 15:56

2 Answers2

2

Just use the new date function.

new Date();

Also, consider taking a look at momentJS for all your javascript date needs.

Lefka
  • 633
  • 6
  • 20
2

This is an ISO-formatted date, so use toISOString.

new Date().toISOString()
  "2015-12-23T15:50:18.134Z"
user513951
  • 12,445
  • 7
  • 65
  • 82