Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date in milliseconds to iso format javascript? [duplicate]

Tags:

javascript

Possible Duplicate:
How do I output an ISO-8601 formatted string in Javascript?

If I have an integer that represents a date in milliseconds, what is the syntax to convert this to an iso format?

like image 572
Rolando Avatar asked Dec 26 '12 20:12

Rolando


People also ask

How do I convert a date to an ISO?

The date. toISOString() method is used to convert the given date object's contents into a string in ISO format (ISO 8601) i.e, in the form of (YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss.

How do you convert milliseconds to date format?

Use the Date() constructor to convert milliseconds to a date, e.g. const date = new Date(timestamp) . The Date() constructor takes an integer value that represents the number of milliseconds since January 1, 1970, 00:00:00 UTC and returns a Date object.

What is ISO 8601 date format JavaScript?

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ , respectively). The timezone is always zero UTC offset, as denoted by the suffix Z .

Is ISO and UTC same?

ISO 8601: It is a representation of dates to keep an international standard and avoid difficulties when handling dates and time. UTC: It is the official time standard to synchronize the clocks and keep precision in measurements and other activities.


1 Answers

Check out the Date object:

new Date(ms).toISOString()

Notice that this method might not be available in older browsers, but you can shim it for them.

like image 177
Bergi Avatar answered Sep 25 '22 09:09

Bergi