10 examples of 'javascript convert utc to specific timezone' in JavaScript

Every line of 'javascript convert utc to 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
42function utcToLocal(utc)
43{
44 return new window.BrowserAutomationStudio_OriginalDate(utc.getTime() - TimezoneOffset*60*1000);
45}
30function getTimeZone(tz) {
31 return (tz == null) ? -new Date().getTimezoneOffset() : tz;
32}
20private convertTimezone(tz: string): number {
21 if (tz == "Z") return 0;
22
23 var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/);
24
25 if (m) {
26 return (m[1] == '-' ? -1 : 1) * (parseInt(m[2], 10) + ((m[3] ? parseInt(m[3], 10) : 0) / 60)) * 60;
27 }
28
29 return 0;
30}
17function setTimeZone() {
18 const indianTimeZone = moment
19 .utc()
20 .add(5, "hours")
21 .add(30, "minutes");
22 return indianTimeZone;
23}
5export function fromUTC (utcHour) {
6 return moment.utc(utcHour, 'H').local()
7}
4function treatAsUtc(dateStr) {
5 let result = new Date(dateStr);
6 result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
7 return result;
8}
50offset(ts) {
51 return -new Date(ts).getTimezoneOffset();
52}
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}
21export function dateToUTC(timestamp) {
22 const date = new Date(timestamp * 1000);
23 return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
24 date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
25}
10export function inferTimezone(current: string | undefined): string {
11 if (current) {
12 return current;
13 }
14 const browserTime = maybeResolveTZ();
15 if (browserTime) {
16 if (ONLY_ONCE.need_to_talk) {
17 alert(t(Content.TIMEZONE_GUESS_BROWSER));
18 ONLY_ONCE.need_to_talk = false;
19 }
20 // WARNING SIDE EFFECTS!!!
21 return browserTime;
22 }
23 if (ONLY_ONCE.need_to_talk) {
24 alert(t(Content.TIMEZONE_GUESS_UTC));
25 ONLY_ONCE.need_to_talk = false;
26 }
27 return "UTC";
28}

Related snippets