代码:
复制代码 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js怎么获取时间差?js时间差计算代码 - www.plcxue.com</title>
<script>
<!--
window.onload = function (){
//定义当前时间
var myYear = 2003;
var myMonth = 08;
var myDay = 29;
var myHour = 04;
var myMinute = 23;
var mySecond = 45;
var myDate = "历史时间:"+myYear+"年"+myMonth+"月"+myDay+"日"+myHour+"时"+myMinute+"分"+mySecond+"秒";
//获取现在时间
var now =new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
if (month<10){
month="0"+month;
}
if (day<10){
day="0"+day
}
if (second<0){
second="0"+second
}
var nowTime = "现在时间:"+year+"年"+month+"月"+day+"日"+hour+"时"+minute+"分"+second+"秒";
alert(myDate);
alert(nowTime);
//如何获取时间差?
}
-->
</script>
</head>
<body></body></html>