![]() |
VOOZH | about |
The moment().zone() method is used to specify the given Moment object's time zone offset in minutes. An optional parameter can be passed that preserves the current time value and only changes the timezone offset.
Syntax:
moment().zone( Number | String );
Parameters: This method accepts a single parameter as mentioned above and described below:
Return Value: This method returns the Moment object with the new offset.
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.
Installation of moment module: Moment.js can be installed using the following command:
npm install moment
Example 1: The below examples will demonstrate the Moment.js moment().zone() Method.
Output:
Timezone Offset of MomentOne: 120 MomentOne is: Moment<2022-08-05T12:02:41-02:00> Timezone Offset of momentTwo: 240 MomentTwo is: Moment<2022-08-05T10:02:41-04:00> Timezone Offset of momentThree: -350 MomentThree is: Moment<2022-08-05T19:52:41+05:50>
Example 2: The below examples will demonstrate the Moment.js moment().zone() Method.
Output:
Timezone Offset of moment1: 540 moment1 is: Moment<2022-08-05T05:02:41-09:00> Timezone Offset of moment2: 180 moment2 is: Moment<2022-08-05T11:02:41-03:00> Timezone Offset of moment3: -480 moment3 is: Moment<2022-08-05T22:02:41+08:00>
Reference: https://momentjs.com/docs/#/manipulating/timezone-offset/