import { Layout } from "@/components/Layout"; import type { Route } from "./+types/time-calculator"; import { useEffect, useState } from "react"; import { Input } from "@/components/ui/input"; import { formatDateTime } from "@/components/SearchResults"; export default function Home() { const now = new Date(); const [time1Input, setTime1Input] = useState(formatDateTime(now)); const [time2Input, setTime2Input] = useState(formatDateTime(now)); const time1 = new Date(time1Input); const time2 = new Date(time2Input); const difference = time2.getTime() - time1.getTime(); const days = Math.floor(difference / (1000 * 60 * 60 * 24)); const hours = Math.floor(difference / (1000 * 60 * 60)); const minutes = Math.floor((difference / (1000 * 60)) % 60); const diffString = `${days || 0} 天 ${hours || 0} 时 ${minutes || 0} 分`; return (

时间计算器

在下方输入两个时间点,即可得到两个时间点之间的时间差

setTime1Input(e.target.value)} /> setTime2Input(e.target.value)} />

{diffString}

); }