Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

133
Views
Why moment-timezone returns wrong utcOffset

For some timezones results that give utcOffset and moment() are different, ie for Europe/Belgrade. Currently it is GMT+2:

`Now: ${currentMoment.format()}`
// Now: 2022-06-09T12:12:08+03:00

moment.tz.zone("Europe/Belgrade").utcOffset(moment().unix())
// -60 - wrong, 1hr

moment.tz("Europe/Belgrade").format()
// 2022-06-09T11:07:03+02:00 - correct

Sandbox

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

Answer is here https://github.com/moment/moment-timezone/issues/989.

Instead of unix()

moment.tz.zone("Europe/Belgrade").utcOffset(moment().unix())

it is correct to use valueOf()

moment.tz.zone("Europe/Belgrade").utcOffset(moment().valueOf())
7 months 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 job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.