update datetime

This commit is contained in:
lb 2023-07-02 16:32:34 +08:00
parent 8f3a94f431
commit d18ba333a5

View File

@ -1,68 +1,50 @@
import React, { useEffect, useState, useRef } from 'react' import React, { useEffect, useState, useRef } from 'react';
import TopSide from "../../assets/TopSide.png" import TopSide from '../../assets/TopSide.png';
import LeftLine from "../../assets/TopTitleLeftIcon.png" import LeftLine from '../../assets/TopTitleLeftIcon.png';
import RightLine from "../../assets/TopTitleRightIcon.png" import RightLine from '../../assets/TopTitleRightIcon.png';
import ButtonLine from "../../assets/TopButtonLine.png" import ButtonLine from '../../assets/TopButtonLine.png';
import './index.less' import './index.less';
export default function index() { export default function index() {
const timmer = useRef() const [now, setNow] = useState('2023.07.01 12:00:00');
const [Hour, setHour] = useState('');
const [Seconds, setSeconds] = useState('');
const [Minutes, setMinutes] = useState('');
const [Year, setYear] = useState('');
const [Month, setMonth] = useState('');
const [Day, setDay] = useState('');
const getNewDate = () => { useEffect(() => {
const time = new Date(); setInterval(() => {
const year = time.getFullYear(); const now = new Date();
const month = time.getMonth() + 1; setNow(
const day = time.getDate(); now
const hour = time.getHours(); .toLocaleDateString('zh-hans', {
const minutes = time.getMinutes(); year: 'numeric',
const s = time.getSeconds(); month: '2-digit',
const seconds = s <= 9 ? "0" + s : s; day: '2-digit',
// const t = `${year}${month}${day} ${hour}:${minutes}:${seconds}` hour: '2-digit',
setHour(hour) minute: '2-digit',
setSeconds(seconds) second: '2-digit',
if (minutes < 10) { })
setMinutes(`0${minutes}`) .replaceAll('/', '.'),
} else { );
setMinutes(minutes) }, 1000);
} }, []);
setYear(year)
setMonth(month)
setDay(day)
} return (
<div className="TopTitleBoder">
useEffect(() => { <img src={TopSide} alt="图片丢失" className="TopSideLeft" />
timmer.current = setInterval(getNewDate, 1000); <div className="TopSideLeftLine">
return () => { <img src={LeftLine} alt="图片丢失" className="TopSideLeftLineicon" />
clearTimeout(timmer.current) <h2 className="TopSideLeftTxt">单位中建材智能自动化研究院</h2>
} </div>
// eslint-disable-next-line <div>
}, []) <h2 className="TopTitleText">
许昌安彩新能科技&ensp;&ensp;4800万方光伏轻质基板生产线{' '}
</h2>
return ( <img src={ButtonLine} alt="图片加载错误" className="TopButtonLine" />
<div className='TopTitleBoder' > </div>
<img src={TopSide} alt="图片丢失" className='TopSideLeft' /> <div className="TopSideRightLine">
<div className='TopSideLeftLine' > <h2 className="TopSideRightTxt">{now}</h2>
<img src={LeftLine} alt="图片丢失" className='TopSideLeftLineicon' /> <img src={RightLine} alt="图片丢失" className="TopSideRightLineicon" />
<h2 className='TopSideLeftTxt'>单位中建材智能自动化研究院</h2> </div>
</div> <img src={TopSide} alt="图片丢失" className="TopSideRight" />
<div > </div>
<h2 className='TopTitleText'>许昌安彩新能科技&ensp;&ensp;4800万方光伏轻质基板生产线 </h2> );
<img src={ButtonLine} alt="图片加载错误" className='TopButtonLine' />
</div>
<div className='TopSideRightLine' >
<h2 className='TopSideRightTxt'>{Year}.{Month}.{Day} {Hour}.{Minutes}.{Seconds}</h2>
<img src={RightLine} alt="图片丢失" className='TopSideRightLineicon' />
</div>
<img src={TopSide} alt="图片丢失" className='TopSideRight' />
</div>
)
} }