JS怎么把时间推迟

JS怎么把时间推迟,第1张

var d = new Date()//实例化日期对象

var dateTimeNow = d.getFullYear() +( d.getMonth() + 1) +d.getDate() + (d.getHours() +1)+ d.getMinutes() + d.getSeconds()

得到的是当前时间的后一个小时的时间

<html>

<head>

<title>JS时间累加</title>

<script type="text/javascript">

function RunTime()

{

var now = new Date()

//当前时间

var hours = now.getHours()//时

var minutes = now.getMinutes()//分

var seconds = now.getSeconds()//秒

document.getElementById("NowTime").innerHTML = hours+"时"+minutes+"分"+seconds+"秒"

//秒加时

now = new Date(now.getTime() + (1000*parseInt(document.getElementById("Jtime").value)))//这里是关键

var hoursS = now.getHours()//时

var minutesS = now.getMinutes()//分

var secondsS = now.getSeconds()//秒

document.getElementById("oldTime").innerHTML = hoursS+"时"+minutesS+"分"+secondsS+"秒"

}

</script>

<style type="text/css">

.style1

{

width: 133px

}

</style>

</head>

<body onload="javascript:document.all('Jtime').focus()">

<table align="center">

<tr><td class="style1">当前时间:</td><td colspan="2"><label id="NowTime"></label></td></tr>

<tr><td class="style1">加时之后:</td><td colspan="2"><label id="oldTime"></label></td></tr>

<tr><td class="style1">输入加入时间/秒:</td><td><input id="Jtime"/></td><td><button id="BtnTime" name="BtTime" onclick="RunTime()">计算</button></td></tr>

</table>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6449053.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-22
下一篇 2023-03-22

发表评论

登录后才能评论

评论列表(0条)

保存