javascripttimezonedsttimezone-offset

javascript - check if daylight time is in effect for different timezone


There are many solutions available in javascript to check whether the date is in daylight or not [ How to check if the DST (Daylight Saving Time) is in effect and if it is what's the offset? ].

But that solutions work only when someone is in the same time zone where daylight effect is applicable, ex. Suppose my current browser (client) is in IST (Indian standard - where there is no daylight time change) and I want to check whether the date is in daylight or not for ET (Eastern time - where daylight is -5 and standard is -4). Above solution (from link) would give me correct result only if my systems time zone is in ET not IST.

How can I calculate it?


Solution

  • If you use moment.js and it's companion timezome script, they make checking for DST pretty easy:

    Check out their docs for isDST()

    Just for grins, here's a fiddle testing each timezone

    if( moment.tz("America/New_York").isDST() ){
        $('#test').append('NY is currently in DST');
    }
    else{
        $('#test').append('NY is NOT currently in DST');
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
    <script src="http://momentjs.com/downloads/moment-timezone-with-data.min.js"></script>
    
    
    
    <div id="test"></div>