Open In App

Moment.js Parsing Unix Timestamp (seconds)

Last Updated : 18 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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/


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads