The Wayback Machine - https://web.archive.org/web/20220910223555/https://www.geeksforgeeks.org/moment-js-parsing-unix-timestamp-seconds/
Skip to content
Related Articles

Related Articles

Moment.js Parsing Unix Timestamp (seconds)

View Discussion
Improve Article
Save Article
  • Last Updated : 18 Jun, 2022
View Discussion
Improve Article
Save Article

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/

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!