在html的使用中javascript是必不可少的
今天来处理时间
1.时间戳转换为年月日 时分秒
var ddd=new Date(parseInt(1551228152) * 1000).toLocaleString() alert(ddd);2.时间戳转换成天时分秒
2.1秒级别
function formatDuring(s){ var days = parseInt(s / (60 * 60 * 24)); var hours = parseInt((s % (60 * 60 * 24)) / (60 * 60)); var minutes = parseInt((s % (60 * 60)) / 60); var seconds = (s%60); return days + "天" + hours + "小时" + minutes + "分钟"+seconds+"秒钟"; } var qq=formatDuring(259204); alert(qq);2.2毫秒级别
function formatDuring(ms){ var days = parseInt(ms / (1000 * 60 * 60 * 24)); var hours = parseInt((ms % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = parseInt((ms % (1000 * 60 * 60)) / (1000 * 60)); var seconds = (ms % (1000 * 60)) / 1000; return days + "天 " + hours + "小时" + minutes + "分钟 "+seconds+"秒"; } var qq=formatDuring(259204); alert(qq);
评论