'use client' import { useEffect, useState } from 'react' export function RealtimeClock() { const [date, setDate] = useState(null) // Start null to avoid hydration mismatch useEffect(() => { setDate(new Date()) // Set initial date on client const timer = setInterval(() => { setDate(new Date()) }, 1000) return () => clearInterval(timer) }, []) if (!date) { // Render a placeholder or nothing during SSR/initial mount to prevent flicker return (
00:00:00 WIB
LOADING...
) } const formattedTime = date.toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit', second: '2-digit' }).replace(/\./g, ':') const formattedDate = date.toLocaleDateString('id-ID', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }).toUpperCase() return (
{formattedTime} WIB
{formattedDate}
) }