Skip to content

Commit 515f5bf

Browse files
committed
Updated clock.tsx
1 parent 5db85a0 commit 515f5bf

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/components/clock/Clock.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import "./clock.css";
66
export default function Clock() {
77
const [time, setTime] = useState(new Date());
88

9+
const getTimeString = (value: Date) => {
10+
// show the colon for two seconds, then hide for one second
11+
// there's probably a better way to do this but i wanted to show the clock was "running"
12+
const showColon = value.getSeconds() % 3 !== 2;
13+
const formatted = value.toLocaleTimeString('en-US', { hour: "numeric", minute: "numeric" });
14+
if (showColon) {
15+
return formatted.replace(':', ' ');
16+
}
17+
return formatted;
18+
};
19+
920
useEffect(() => {
1021
const interval = setInterval(() => {
1122
setTime(new Date());
@@ -18,7 +29,7 @@ export default function Clock() {
1829
<>
1930
<section className="clock">
2031
<div className="clock-container">
21-
<p>{time.toLocaleDateString('en-US', { month: "numeric", day: "numeric" })} {time.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })}</p>
32+
<p>{time.toLocaleDateString('en-US', { month: "numeric", day: "numeric" })} {getTimeString(time)}</p>
2233
</div>
2334
</section>
2435
</>

0 commit comments

Comments
 (0)