Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get Timezone Offset in String format Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 864
    Comment on it

    Get Timezone Offset in String Format Javascript

     

    Hi Friends,
    If we want to retrieve timezone in string format like Asia/Calcutta or America/New_York in javascript. Javascript's method getTimezoneOffset() just return the offsets or you are needed to use plugin like moment.js or similar but if you don't want that you can just write your own function like this.

     

     
        function getTimeZone() {
            var offset = (new Date()).getTimezoneOffset();
            var timezones = {
                "-12": "Pacific/Kwajalein",
                "-11": "Pacific/Samoa",
                "-10": "Pacific/Honolulu",
                "-9": "America/Juneau",
                "-8": "America/Los_Angeles",
                "-7": "America/Denver",
                "-6": "America/Mexico_City",
                "-5": "America/New_York",
                "-4": "America/Caracas",
                "-3.5": "America/St_Johns",
                "-3": "America/Argentina/Buenos_Aires",
                "-2": "Atlantic/Azores",
                "-1": "Atlantic/Azores",
                "0": "Europe/London",
                "1": "Europe/Paris",
                "2": "Europe/Helsinki",
                "3": "Europe/Moscow",
                "3.5": "Asia/Tehran",
                "4": "Asia/Baku",
                "4.5": "Asia/Kabul",
                "5": "Asia/Karachi",
                "5.5": "Asia/Calcutta",
                "6": "Asia/Colombo",
                "7": "Asia/Bangkok",
                "8": "Asia/Singapore",
                "9": "Asia/Tokyo",
                "9.5": "Australia/Darwin",
                "10": "Pacific/Guam",
                "11": "Asia/Magadan",
                "12": "Asia/Kamchatka"
            };
            return timezones[-offset / 60];
        }
    


    Hope you liked it. For more like this. For more blogs like this Click here.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: