|
|
@ -13,26 +13,31 @@ import { |
|
|
|
} from '@/components/ui/select'; |
|
|
|
} from '@/components/ui/select'; |
|
|
|
|
|
|
|
|
|
|
|
const TIMEZONE_LIST = ['Asia/Seoul', 'America/New_York', 'Europe/London', 'Asia/Tokyo']; |
|
|
|
const TIMEZONE_LIST = ['Asia/Seoul', 'America/New_York', 'Europe/London', 'Asia/Tokyo']; |
|
|
|
|
|
|
|
const INTERVAL = 500; |
|
|
|
|
|
|
|
|
|
|
|
export default function Home() { |
|
|
|
export default function Home() { |
|
|
|
const [now, setNow] = useState(DateTime.now()); |
|
|
|
const [now, setNow] = useState(DateTime.now()); |
|
|
|
const [timezone, setTimezone] = useState('Asia/Seoul'); |
|
|
|
const [timezone, setTimezone] = useState('Asia/Seoul'); |
|
|
|
|
|
|
|
const [defNow, setDefNow] = useState(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const timer = setInterval(() => setNow(DateTime.now()), 10); |
|
|
|
const timer = setInterval(() => { |
|
|
|
|
|
|
|
setNow(DateTime.now()); |
|
|
|
|
|
|
|
setDefNow(new Date()); |
|
|
|
|
|
|
|
}, INTERVAL); |
|
|
|
return () => clearInterval(timer); |
|
|
|
return () => clearInterval(timer); |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
const localNow = now.setZone(timezone); |
|
|
|
const localNow = timezone ? now.setZone(timezone) : now; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<main className="flex min-h-screen flex-col items-center justify-center p-6"> |
|
|
|
<main className="flex min-h-screen flex-col items-center justify-center space-y-10 p-6"> |
|
|
|
<Card className="w-full max-w-md"> |
|
|
|
<Card className="w-full max-w-md"> |
|
|
|
<CardHeader> |
|
|
|
<CardHeader className="flex justify-center"> |
|
|
|
<CardTitle className="text-2xl">DateTime UI Sample</CardTitle> |
|
|
|
<CardTitle className="text-3xl font-bold">DateTime UI Sample</CardTitle> |
|
|
|
</CardHeader> |
|
|
|
</CardHeader> |
|
|
|
<CardContent className="space-y-4"> |
|
|
|
<CardContent> |
|
|
|
<div className="flex flex-col justify-center"> |
|
|
|
<div className="flex flex-col items-center justify-center space-y-4"> |
|
|
|
<Label htmlFor="tz">Select timezone</Label> |
|
|
|
<Label htmlFor="tz">Select timezone</Label> |
|
|
|
<Select value={timezone} onValueChange={setTimezone}> |
|
|
|
<Select value={timezone} onValueChange={setTimezone}> |
|
|
|
<SelectTrigger id="tz" className="mt-1"> |
|
|
|
<SelectTrigger id="tz" className="mt-1"> |
|
|
@ -46,13 +51,15 @@ export default function Home() { |
|
|
|
))} |
|
|
|
))} |
|
|
|
</SelectContent> |
|
|
|
</SelectContent> |
|
|
|
</Select> |
|
|
|
</Select> |
|
|
|
|
|
|
|
<div className="flex flex-col items-center font-mono text-teal-600"> |
|
|
|
|
|
|
|
<p>Current time: {localNow.toFormat('yyyy-MM-dd HH:mm:ss (ZZZZ)')}</p> |
|
|
|
|
|
|
|
<p>Now: {now.toFormat('yyyy-MM-dd HH:mm:ss (ZZZZ)')}</p> |
|
|
|
|
|
|
|
<p>Default date now: {defNow.toISOString()}</p> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="text-primary font-mono text-lg"> |
|
|
|
<div className="text-xs opacity-60"> |
|
|
|
Current time: {localNow.toFormat('yyyy-MM-dd HH:mm:ss (ZZZZ)')} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<div className="text-muted-foreground text-xs"> |
|
|
|
|
|
|
|
(Luxon: realtime rendering, local timezone support) |
|
|
|
(Luxon: realtime rendering, local timezone support) |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
</CardContent> |
|
|
|
</CardContent> |
|
|
|
</Card> |
|
|
|
</Card> |
|
|
|
<h1 className="mb-6 text-3xl font-bold">DateTime UI Sample</h1> |
|
|
|
<h1 className="mb-6 text-3xl font-bold">DateTime UI Sample</h1> |
|
|
|