首页 > 其他分享 >JS秒转换为天小时分秒公式&返回当前年月日时分秒&度分秒转换

JS秒转换为天小时分秒公式&返回当前年月日时分秒&度分秒转换

时间:2023-01-12 14:12:16浏览次数:63  
标签:分秒 3600 转换 floor 60 let date 时分秒 Math

天时分秒

let d = Math.floor(seconds / (3600 * 24));
    let h = Math.floor(seconds % (3600 * 24) / 3600);
    let m = Math.floor(seconds % 3600 / 60);
    let s = Math.floor(seconds % 60);
 
    d = d > 10 ? d : '0' + d
    h = h > 10 ? h : '0' + h
    m = m > 10 ? m : '0' + m
    s = s > 10 ? s : '0' + s
 
--------------------------------------------------------------
d = parseInt(总秒数/ 60/60 /24); // 计算天数
h = parseInt(总秒数/ 60/60 %24) // 计算小时
m = parseInt(总秒数 /60 %60 ); // 计算分数
s = parseInt(总秒数%60); // 计算当前秒数

备注:注意毫秒先转成秒,再用上述方法

 时分秒

let h = Math.floor(d / 3600)
let m = Math.floor(d % 3600 / 60)
let s = Math.floor(d % 3600 % 60)
 
h = h > 10 ? h : '0' + h
m = m > 10 ? m : '0' + m
s = s > 10 ? s : '0' + s

返回当前年月日

    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()
    let hour = date.getHours() + 1
    let minute = date.getMinutes()
    let second = date.getSeconds()

 

 

      //   小时角度公式:小时 * 30 + 分钟 / 60 * 30 
      //   分钟角度公式:分钟* 6 + 秒 / 60 * 6
      //   秒角度公式: 当前秒数 * 6
      hour.style.transform = `rotate(${hh * 30 + mm / 60 * 30}deg)`;
      minute.style.transform = `rotate(${mm * 6 + ss / 60 * 6}deg)`;
      second.style.transform = `rotate(${ss * 6}deg)`;

 

参考:https://blog.csdn.net/qq_46269308/article/details/126024507

标签:分秒,3600,转换,floor,60,let,date,时分秒,Math
From: https://www.cnblogs.com/mmzuo-798/p/17046524.html

相关文章