VOOZH about

URL: https://www.geeksforgeeks.org/node-js/moment-js-moment-tostring-method/

⇱ Moment.js moment().toString() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Moment.js moment().toString() Method

Last Updated : 28 Jun, 2022

The moment().toString() Method is used to return a human-readable string of the Moment object in English. It is similar to the native Date object's toString() method. The date return contains the Weekday, Month, Day, Year, Time and Timezone Offset.

Syntax:

moment().toString();

Parameters: This method does not accept any parameters:

Return Value: This method returns the Moment as a string.

Note: This will not work in the normal Node.js program because it requires an external moment.js library to be installed globally or in the project directory.

Moment.js can be installed using the following command:

Installation of moment module:

npm install moment

The below examples will demonstrate the Moment.js moment().toString() Method.

Example 1:

Output:

MomentOne toString(): Tue Jun 28 2022 02:23:53 GMT+0530
MomentTwo toString(): Mon Jan 10 2022 00:00:00 GMT+0530
MomentThree toString(): Tue Jun 28 2022 05:15:44 GMT+0530

Example 2:

Output:

Moment1 toString(): Mon Jun 28 2010 02:17:48 GMT+0530
Moment2 toString(): Thu Jul 08 2010 02:17:48 GMT+0530
Moment3 toString(): Thu Jul 08 2010 22:17:48 GMT+0530

Reference: https://momentjs.com/docs/#/displaying/as-string/

Comment

Explore