验证中...
时间格式在安卓和ios的不同展示情况
Raw Copy
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
剩余时间
<div id="theTime">
</div>
<div id="">
结束时间
</div>
<div id="endTime">
</div>
<button id="clearTheTime">清理时间</button>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
// 标准时间 相减 转时间戳
$("#endTime").text(Math.abs((new Date("2019/03/20 10:28:54") - new Date())))
// 修改的时间格式
let standardTime = "2019-03-20 10:28:54" //这个时间格式在ios下 不支持 显示结果为NAN
standardTime = standardTime.replace(/-/g,"/")// "2019/03/20 10:28:54" 变换后的时间格式 这种时间格式在ios和安卓 显示均为ok
// 接口时间 转时间戳
let stopTime = (new Date(standardTime)).getTime()
console.log(stopTime)
document.write(new Date())
document.write("================================================")
document.write(standardTime)
let nowTime
let residueTime
var theTimeInte
// 时间转换
function formatDuring(mss) {
var days = parseInt(mss / (1000 * 60 * 60 * 24));
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
var seconds = (mss % (1000 * 60)) / 1000;
return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + "s";
}
theTimeInte = setInterval(function(){
// 当前时间戳
nowTime = Date.parse(new Date())
// 时间差
residueTime = stopTime - nowTime
formatDuring(residueTime)
console.log(formatDuring(residueTime))
$("#theTime").text(formatDuring(residueTime))
},1000)
// 清理定时器
$("#clearTheTime").on('click',function(){
window.clearInterval(theTimeInte)
})
</script>
</body>
</html>

Comment list( 0 )

You need to Sign in for post a comment

Help Search