Moment.js Parsing Unix Timestamp (milliseconds)
Moment.js is a date library for JavaScript that parses, validates, manipulates, and formats dates. We can use the moment() function to parse unix timestamps (milliseconds).
The moment() function is used to create a moment using Unix Timestamp, milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).
Syntax:
moment( Number )
Parameter: It takes a Number variable which is the number of milliseconds after the Unix Epoch.
Return Value: It returns a Moment object.
Example 1:
Javascript
import moment from 'moment' ; let date = moment(883982892788); console.log(date.format( "DD/MM/YYYY" )); |
Output:
Example 2:
Javascript
import moment from 'moment' ; let date = moment(1624603283892); console.log(date.format( "dddd, Do MMM YYYY, h:mm:ss A" )); |
Output:
Reference: https://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/