Moment.js moment.second() Method
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 accepts a single parameter number that you want to set seconds then you will require an additional parameter:
- Number: It ranges from 0 to 59 and is 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
const moment = require( 'moment' );
let sec = moment().second();
console.log( "Current seconds Time:" , sec);
|
Output:
Current seconds Time: 18
Example 2: Setting seconds of time.
Javascript
const moment = require( 'moment' );
let 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>
Last Updated :
20 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...