blob: 053147bf42ec41681e32335438bce477a37e9b56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { useEffect, useState } from "preact/hooks";
const dateTimeFormat = new Intl.DateTimeFormat();
const timezoneId = Temporal.Now.timeZoneId();
export function Time() {
const [time, setTime] = useState(Temporal.Now.instant().toZonedDateTimeISO(timezoneId))
useEffect(() => {
const id = setInterval(() => {
setTime(time => time.add({ seconds: 1 }));
}, 1000)
return () => {
clearInterval(id);
}
}, [])
return <div id="time">
<div>{dateTimeFormat.format(time.toPlainTime())}</div>
<div>{dateTimeFormat.format(time.toPlainDate())}</div>
</div>
}
|