import React, { useEffect, useState } from 'react'
import './index.less'



const Time = (props: any) => {

  // 时间定时器
  let currentTimeChange = null as any


  const [currentTime, setCurrentTime] = useState(new Date()) as any // 时间

  useEffect(() => {
    init() // 初始化
    return () => {
      clearInterval(currentTimeChange) // 清楚定时器
    }
  }, [])

  //初始化three.js相关内容
  const init = () => {
    // 更新时间
    currentTimeChange = setInterval(() => {
      setCurrentTime(new Date()) // 更新时间
    }, 1000)
  }

  return (
    <>
      <div id="Time" className='time'>
        <span style={{ color: '#1395E8' }}>  {currentTime.toLocaleDateString()} </span>  <span style={{ color: '#1395E8' }}>{currentTime.toLocaleTimeString()}</span>
      </div>
    </>
  )
}
export default React.memo(Time)
