“JavaScript Uzyskaj lokalną strefę czasową” Kod odpowiedzi

Zdobądź stref time JavaScript

const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(timezone);
Indonesia People

JavaScript Uzyskaj określoną strefę czasową

function changeTimezone(date, ianatz) {

  // suppose the date is 12:00 UTC
  var invdate = new Date(date.toLocaleString('en-US', {
    timeZone: ianatz
  }));

  // then invdate will be 07:00 in Toronto
  // and the diff is 5 hours
  var diff = date.getTime() - invdate.getTime();

  // so 12:00 in Toronto is 17:00 UTC
  return new Date(date.getTime() - diff); // needs to substract

}

// E.g.
var here = new Date();
var there = changeTimezone(here, "America/Toronto");

console.log(`Here: ${here.toString()}\nToronto: ${there.toString()}`);
 Run code snippetHide results
Troubled Trout

Jak zobaczyć moją strefę czasową za pomocą JS

document.getElementById("time").innerHTML = Date().slice(Date().indexOf("(")+1,Date().lastIndexOf(")"));
Butty Code

JavaScript Uzyskaj lokalną strefę czasową

{timeZone: `${Intl.DateTimeFormat().resolvedOptions().timeZone}`}
Yellowed Yacare

Odpowiedzi podobne do “JavaScript Uzyskaj lokalną strefę czasową”

Pytania podobne do “JavaScript Uzyskaj lokalną strefę czasową”

Więcej pokrewnych odpowiedzi na “JavaScript Uzyskaj lokalną strefę czasową” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu