The moment().unix() function is used to get the number of seconds since the Unix Epoch. Basically the Unix time is a system for describing a point in time.
Syntax:
moment().unix();
Parameters: This function has no parameter.
Return Value: This function returns the Unix Timestamp in seconds.
Installation of moment module:
- You can visit the link to Install moment module. You can install this package by using this command.
npm install moment
- After installing the moment module, you can check your moment version in command prompt using the command.
npm version moment
- After that, you can just create a folder and add a file for example, index.js as shown below.
Example 1: Filename: index.js
// Requiring the module const moment = require('moment'); // Function call var result = moment().unix(); console.log("Result:", result) |
Steps to run the program:
- The project structure will look like this:

- Run index.js file using below command:
node index.js
Output:
Result: 1595007379
Example 2: Filename: index.js
// Requiring the module const moment = require('moment'); function getUnixTimeStamp() { return moment().unix(); } // Function call var result = getUnixTimeStamp(); console.log("Unix Timestamp in seconds:", result) |
Steps to run the program:
- The project structure will look like this:

- Run index.js file using below command:
node index.js
Output:
Unix Timestamp in seconds: 1595007321
Reference: https://momentjs.com/docs/#/displaying/unix-timestamp/
Recommended Posts:
- How to get the function name from within that function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- D3.js easePolyOut Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

