import { useEffect, useState } from "react";

const Timer = () => {
  const [times, setTimes] = useState<any>();

  const updateTime = () => {
    const date = new Date();
    const month = (date.getMonth() + 1).toString().padStart(2, "0");
    const strDate = date.getDate().toString().padStart(2, "0");
    const starHours = date.getHours().toString().padStart(2, "0");
    const starMinutes = date.getMinutes().toString().padStart(2, "0");
    const starSeconds = date.getSeconds().toString().padStart(2, "0");
    const format = `${date.getFullYear()}-${month}-${strDate} 
        ${starHours}:${starMinutes}:${starSeconds}`;
    setTimes(format);
  };
  useEffect(() => {
    let tim = setInterval(updateTime, 1000);
    return () => {
      clearInterval(tim);
    };
  }, []);
  return <span style={{fontSize:"1rem"}}>{times} </span>;
};

export default Timer;
