Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I get timeZone name by offset?

I want to get the list of timeZoneIds (like: America/Los_Angeles) that at there, the time is 10am

So if UTC time is 1am, I will get all timezones of GMT +9 or offset = 10 * 60 * 60

How I can do it with moment.js ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

now = moment()
zones_at_10 = moment.tz.names().filter(zone => now.tz(zone).hour() == 10)

This will get all zones where the hour is currently 10 (including those where it is 10:01 as well as those where it is 10:31). If you wish to restrict to only the zones where it is currently 10:00, you can use this instead:

zones_at_10 = moment.tz.names().filter(zone => now.tz(zone).format("H:s") == "10:00")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading