11 lines
337 B
TypeScript
11 lines
337 B
TypeScript
|
|
import { useState, useEffect } from "react";
|
||
|
|
|
||
|
|
export function useLocalTimezone() {
|
||
|
|
const [tz, setTz] = useState("");
|
||
|
|
useEffect(() => {
|
||
|
|
const parts = Intl.DateTimeFormat(undefined, { timeZoneName: "short" }).formatToParts(new Date());
|
||
|
|
setTz(parts.find((p) => p.type === "timeZoneName")?.value ?? "");
|
||
|
|
}, []);
|
||
|
|
return tz;
|
||
|
|
}
|