10 examples of 'javascript get timezone offset for specific timezone' in JavaScript

Every line of 'javascript get timezone offset for specific timezone' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
50offset(ts) {
51 return -new Date(ts).getTimezoneOffset();
52}
30function getTimeZone(tz) {
31 return (tz == null) ? -new Date().getTimezoneOffset() : tz;
32}
6function timezoneAbbr(date){
7 // Date.toString gives different results depending on the
8 // browser/system so we fallback to timezone offset
9 // chrome: 'Mon Apr 08 2013 09:02:04 GMT-0300 (BRT)'
10 // IE: 'Mon Apr 8 09:02:04 UTC-0300 2013'
11 var tz = /\(([A-Z]{3,4})\)/.exec(date.toString());
12 return tz? tz[1] : timezoneOffset(date);
13}
49function timeZoneGetter(date) {
50 var zone = -1 * date.getTimezoneOffset();
51 var paddedZone = (zone >= 0) ? "+" : "";
52
53 paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) +
54 padNumber(Math.abs(zone % 60), 2);
55
56 return paddedZone;
57}
113function timeZoneName(date) {
114 var result = /\((.*)\)/.exec(date.toString());
115 var language;
116
117 if (this.navigator != null) {
118 language = this.navigator.userLanguage || this.navigator.language;
119 }
120
121 if (result && result.length > 1) {
122 return result[1];
123 } else {
124 if (language === undefined) {
125 return null;
126 }
127
128 // Try 2nd way, using the locale string, this does not work in Safari (26.07.2016)
129 try {
130 var localeString = date.toLocaleString(language, { timeZoneName: "short" });
131 result = localeString.split(" ");
132 return result[result.length - 1];
133 } catch (e) {
134 return null;
135 }
136 }
137}
1867tzOffset: function tzOffset(date) {
1868 return date.getTimezoneOffset() * 60 * 1000;
1869},
60function browserTimezone() {
61 var tzMatch = /.+\(([A-Z]+)\)/.exec(new Date().toString());
62 return tzMatch[1] || "";
63}
1function getUTCOffset() {
2 // This gives us our UTC offset in minutes, but negative.
3 var tz_offset = (new Date()).getTimezoneOffset();
4 var logstr = " ** getUTCOffset(): minutes=" + tz_offset;
5
6 var is_negative = true; // Reversed, because we have an offset in the wrong direction.
7 if (tz_offset < 0) {
8 is_negative = false;
9 tz_offset *= -1;
10 }
11
12 // Now we have a positive offset, which is much nicer to work with.
13 var offset_minutes = tz_offset % 60;
14 var offset_hours = (tz_offset - offset_minutes) / 60;
15 var offset_number = (offset_hours * 100) + offset_minutes;
16
17 // Make a string with zero padding.
18 var offset_str = offset_number.toString();
19 if (offset_str.length == 3) {
20 offset_str = "0" + offset_str;
21 }
22
23 if (is_negative) {
24 offset_str = "-" + offset_str;
25 } else {
26 offset_str = "+" + offset_str;
27 }
28
29 console.log(logstr + " offset_str='" + offset_str + "'");
30 return offset_str;
31}
88function getTimezoneOffset() {
89 var offset = new Date().getTimezoneOffset();
90 var minutes = Math.abs(offset);
91 var hours = Math.floor(minutes / 60);
92 var prefix = offset < 0 ? "+" : "-";
93 return prefix + hours;
94}
30function stdTimezoneOffset (date) {
31 var jan = new Date(date.getFullYear(), 0, 20);
32 var jul = new Date(date.getFullYear(), 6, 20);
33 return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
34}

Related snippets