<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>日期对象 </title>
<script type="text/javascript">
var mydate=new Date();
document.write("当前时间:"+mydate+"<br>");
mydate.setTime(mydate.getTime() + 2* 60 * 60 * 1000);
document.write("推迟二小时时间:" + mydate);
</script>
</head>
<body>
</body>
</html>输出结果
当前时间:Thu Oct 20 2016 15:16:27 GMT+0800
推迟二小时时间:Thu Oct 20 2016 17:16:27 GMT+0800
1秒是1000毫秒,一分钟是60秒,一小时是60分钟。一个小时就是60 * 60 * 1000毫秒,两个小时就是60 * 60 * 1000*2毫秒,js中的时间是以毫秒为单位。
get/setTime() 返回/设置时间,单位毫秒数。