Moment.js moment().unix() Function Last Updated : 08 Jan, 2025 Comments Improve Suggest changes Like Article Like Report The function moment().unix() retrieves the count of seconds since the Unix Epoch, which is a reference point for denoting a specific moment in time. Unix time serves as a system for timestamping.Syntax:moment().unix();Parameters: This function has no parameters. Return Value: This function returns the Unix Timestamp in seconds. The moment().unix() function converts dates into Unix timestamps in Moment.js.Steps to create the Express App and Installing the Modules:Step 1: Initializing the Nodejs app using the below command:npm init -yStep 2: Installing the express module:npm install momentProject Structure:The updated dependencies in package.json file will look like:"dependencies": { "moment": "^2.30.1",} Example 1: Below is the code for the moment().unix(): JavaScript // Requiring the module const moment = require('moment'); // Function call let result = moment().unix(); console.log("Result:", result) Steps to run the program:node index.jsOutput:Result: 1595007379Example 2: Below is the code for the moment().unix(): JavaScript // Requiring the module const moment = require('moment'); function getUnixTimeStamp() { return moment().unix(); } // Function call let result = getUnixTimeStamp(); console.log("Unix Timestamp in seconds:", result) Steps to run the program:node index.jsOutput:Unix Timestamp in seconds: 1595007321 Comment More infoAdvertise with us Next Article Moment.js moment().unix() Function G gouravhammad Follow Improve Article Tags : Web Technologies Node.js Moment.js Similar Reads Moment.js moment().to() Function The moment().to() function is used when users want to display a moment in relation to a time other than now. This function calculates the time to a particular date in Node.js. Syntax: moment().to(Moment|String|Number|Date|Array, Boolean); Parameters: This function has two parameters, first one is o 2 min read Moment.js moment().toNow() Function The moment().toNow(Boolean) function is used to calculate the time to now in Node.js. This function is sometimes called time ago or relative time. Syntax: moment().toNow(Boolean); Parameters: This function has one optional boolean type parameter to return the value without a prefix. Return Value: 2 min read Moment.js moment().valueOf() Function The moment().valueOf() function is used to get the number of milliseconds since the Unix Epoch. Basically, Unix time is a system for describing a point in time. Syntax: moment().valueOf(); Parameters: This function has no parameters. Return Value: This function returns the Unix Timestamp in millis 2 min read Moment.js moment().from() Function The moment().from() function is used to calculate the time from any other time in Node.js. It takes a date as a parameter and calculates the time from that date. Syntax: moment().from(Moment|String|Number|Date|Array, Boolean); Parameters: This function accepts two parameters, first is the date para 2 min read Moment.js moment().format() Function The moment().format() function is used to format the date according to the user's need. The format can be provided in string form which is passed as a parameter to this function. Syntax: moment().format(String); Parameters: This function accepts a single parameter of string type, which defines the 2 min read Like