Skip to content
Related Articles

Related Articles

Moment.js moment.second() Method
  • Last Updated : 07 Aug, 2020

The moment().second() Method is used to get the seconds from the current time or to set the seconds.

Syntax:

moment().second();

// or

moment().seconds();

Parameters: This method accept single parameter number that you want to set seconds then you will require an additional parameter:

  • Number: It ranges from 0 to 59 and used to set seconds in a variable.

Return Value: This function returns the current time in seconds.



Note: This will not work in the normal Node.js program because it requires the moment.js library to be installed. 

Moment.js can be installed using the following command:

npm install moment

Example 1: Getting the current time in seconds.

Javascript




// Acquiring the plugin 
const moment = require('moment'); 
  
var sec = moment().second(); 
  
console.log("Current seconds Time:", sec);

Output:

Current seconds Time: 18

Example 2: Setting seconds of time.

Javascript




// Acquiring the plugin 
const moment = require('moment'); 
  
var sec = moment().second(55); 
  
console.log("Seconds Time:", sec);

Output: we can see the seconds in time.

Seconds Time: Moment<2020-08-05T20:59:55+05:30>
My Personal Notes arrow_drop_up
Recommended Articles
Page :