毫秒格式化

 ## 计算当前毫秒数:

 const [start,setStart] = useState(new Date().getTime())
    
    useEffect(()=>{
        setInterval(()=>{
            setCurrMill(new Date().getTime()-start)
        },1)
    },[])

## 格式化毫秒 

 function formatMilliseconds(milliseconds) {
        const totalSeconds = Math.floor(milliseconds / 1000);
        const minutes = Math.floor(totalSeconds / 60);
        const seconds = totalSeconds % 60;
        const centiseconds = Math.floor((milliseconds % 1000) / 10);

        const formattedTime =
            (minutes < 10 ? '0' : '') +
            minutes +
            ':' +
            (seconds < 10 ? '0' : '') +
            seconds +
            '.' +
            (centiseconds < 10 ? '0' : '') +
            centiseconds;

        return formattedTime;
    }

## 显示: 

毫秒格式化_第1张图片

你可能感兴趣的:(前端,linux,javascript)