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

Example 2:
Javascript
import moment from 'moment'; let date = moment.unix(882892788.88);console.log(date.format("DD/MM/YYYY")); |
Output:

Reference: https://momentjs.com/docs/#/parsing/unix-timestamp/


