Open In App

Moment.js Parsing parseZone() Function

Last Updated : 20 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Moment.js Parsing parseZone() function parses the string provided and keeps the resulting moment in a fixed timezone. Furthermore, this method parses the string but keeps the resulting Moment object in a fixed-offset timezone with the provided offset in the string.

Syntax:

moment.parseZone()
moment.parseZone(String)

Parameters:

  • String: The fixed-offset timezone with the provided offset

Returns type: This function will return the Moment object to local or UTC time.

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. For more details, please refer to this link.

Installation of moment module: Moment.js can be installed using the following command.

npm install moment

Example 1: Getting the Current Parse Timezone

index.js

Javascript




// Importing moment module
const moment = require('moment');
let a = moment().parseZone();
console.log("Current parse Timezone: ",a);


Step to run the application: Run the index.js file using the below command.

node index.js

Output:

Current parse Timezone:  Moment<2022-10-08T06:55:05+00:00>

Example: Parsing the timezone

index.js

Javascript




// Importing moment module
const moment = require('moment');
let a = moment("2022-01-01T00:00:00-13:00").utcOffset("2022-01-01T00:00:00-13:00");
let b = moment.parseZone("2022-01-01T00:00:00-13:00");
console.log("Current parse Timezone: ",a)
console.log("Current parse Timezone: ",b)


Step to run the application: Run the index.js file using the below command.

node index.js

Output:

Current parse Timezone:  Moment<2022-01-01T00:00:00-13:00>
Current parse Timezone:  Moment<2022-01-01T00:00:00-13:00>

References: https://momentjs.com/docs/#/parsing/parse-zone/


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads