Skip to content

JavaScript:Intl

IANA Timezone 얻는 방법

import usTZs from "../data/usTZGrouped.json";

export const getMyIANATZ = () => {
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
};

export const getTZGroup = (ianatz = null) => {
  const localTZ = ianatz ? ianatz : getMyIANATZ();
  // fallback
  let currentTZGroup = "US/Pacific";

  usTZs.forEach((item) => {
    if (item.name === localTZ) {
      currentTZGroup = item.group;
    }
  });
  return currentTZGroup;
};

브라우저 에서 타임존 목록 출력하기

Intl.supportedValuesOf('timeZone');

See also