import React, { useEffect, useState } from "react"; import dayjs from "dayjs"; type Props = { format?: string; }; const Index = (props: Props) => { const { format = "YYYY年MM月DD日" } = props; const [time, setTime] = useState(); useEffect(() => { setTime(dayjs().format(format)); const timeInterval = setInterval(() => { setTime(dayjs().format(format)); }, 1000); return () => { clearInterval(timeInterval); } }, []); return ({time}); }; export default Index;