Search code examples
node.jstimezoneutcdstgmt

Get UTC offset and DST information for a specific timezone in node?


I need to get UTC offset and DST information for a specific timezone in node.js. In case i use an external web service, it is necessary that the service used is free with unlimited requests if it's possible.

Example: if i put Europe/Rome timezone as a parameter i need to have 3600 as utc offset and 0 as DST information.

I found timezonedb but there is a rate limit where you can only send request to the server once per second.


Solution

  • For anything time related you should look into using moment.js

    Here is the documentation for moment.js Here is the documentation for moment.js timezone

    Below is taken from the moment.js timezone docs

    var jun = moment("2014-06-01T12:00:00Z");
    var dec = moment("2014-12-01T12:00:00Z");
    
    jun.tz('America/Los_Angeles').format('ha z');  // 5am PDT
    dec.tz('America/Los_Angeles').format('ha z');  // 4am PST
    
    jun.tz('America/New_York').format('ha z');     // 8am EDT
    dec.tz('America/New_York').format('ha z');     // 7am EST
    

    You should be able to find the correct methods based on your use case.