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?
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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With