Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

446
Views
How to retrieve current moment default time zone

If I set default moment time zone with moment.tz.setDefault(), is there a way to later retrieve the current default time zone?

Example:

const moment = require('moment-timezone');

moment.tz.setDefault('Asia/Tokyo');

console.log(moment.tz.getDefault()); // TypeError: moment.tz.getDefault is not a function
console.log(moment.tz.default);      // undefined
console.log(moment.tz.guess());      // America/New_York (my local timezone)
console.log(moment.tz.guess(true));  // America/New_York

// => I want something that will return "Asia/Tokyo"

This is different from the suggested duplicate because I don't want the browser's time zone, I specifically want to know what (if anything) moment.tz.setDefault() was set to.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can achieve that by moment.defaultZone.name:

const moment = require('moment-timezone');

moment.tz.setDefault('Asia/Tokyo');

console.log(moment.defaultZone.name)

Output:

Asia/Tokyo

Update after @Kip comment

  • If no default time zone is set, moment.defaultZone is undefined, so use moment.defaultZone?.name to be safe.
  • Other approach which uses documented functionality is moment().format('ZZ') which returns "+0900" in Tokyo time.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!