![]() |
The moment().utcOffset() method is used to specify the given Moment object’s UTC offset. An optional parameter can be passed that preserves the current time value and only changes the offset. Syntax: moment().utcOffset( Number | String, [Boolean] ); Parameters: This method accepts two parameters 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. 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().utcOffset() Method. Example 1: Javascript
Output: Utc Offset of MomentOne: 60 MomentOne is: Moment<2022-08-05T14:56:08+01:00> Utc Offset of momentTwo: 150 MomentTwo is: Moment<2022-08-05T16:26:08+02:30> Utc Offset of momentThree: -510 MomentThree is: Moment<2022-08-05T05:26:08-08:30> Example 2: Javascript
Output: Utc Offset of moment1: 120 moment1 is: Moment<2022-08-05T15:56:08+02:00> Utc Offset of moment2: 300 moment2 is: Moment<2022-08-05T18:56:08+05:00> Utc Offset of moment3: -360 moment3 is: Moment<2022-08-05T07:56:08-06:00> Reference: https://momentjs.com/docs/#/manipulating/utc-offset/ |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |