"use client"; import React, { useState, useEffect } from "react"; import { useFormatter } from "next-intl"; export default function Time(props: { showSecond: boolean }) { const [currentTime, setCurrentTime] = useState(new Date()); const format = useFormatter(); useEffect(() => { const timer = setInterval(() => { setCurrentTime(new Date()); }, 150); return () => { clearInterval(timer); }; }, []); const formatTime = () => { const hours = currentTime.getHours().toString().padStart(2, "0"); const minutes = currentTime.getMinutes().toString().padStart(2, "0"); const seconds = currentTime.getSeconds().toString().padStart(2, "0"); if (props.showSecond) { return `${hours}:${minutes}:${seconds}`; } else { return `${hours}:${minutes}`; } }; return (
{formatTime()}{" "} {format.dateTime(currentTime, { year: "numeric", month: "short", day: "numeric" })}
); }