这是全部代码。我的是windows Server2003sp2 系统。
var objdate1 = new Date();
var objdate2 = new Date(05,10,36,12,23,02);document.write("<font color='#f02020'>常用时间:</font><br />");
document.write("完整年份:"+objdate1.getFullYear()+"<br />");
document.write("完整年份:"+objdate2.getFullYear()+"<br />");
document.write("年份:"+objdate1.getYear()+"<br />");
document.write("年份:"+objdate2.getYear()+"<br />");
document.write("月份:"+objdate1.getMonth()+"<br />");//从0开始的
document.write("月份:"+objdate2.getMonth()+"<br />");
document.write("日期: "+objdate1.getDate()+"<br />");
document.write("日期:"+objdate2.getDate()+"<br />");
document.write("周:"+objdate1.getDay()+"<br />");//0是星期天
document.write("周:"+objdate2.getDay()+"<br />");
document.write("小时:"+objdate1.getHours()+"<br />");
document.write("小时:"+objdate2.getHours()+"<br /");
document.write("分钟:"+objdate1.getMinutes()+"<br />");
document.write("分钟:"+objdate2.getMinutes()+"<br />");
document.write("秒钟:"+objdate1.getSeconds()+"<br />");
document.write("秒钟:"+objdate2.getSeconds()+"<br />");
document.write("毫秒:"+objdate1.getMilliseconds()+"<br />");
document.write("现在距离1970年1月1日午夜已经有:"+objdate1.getTime()/1000 + "秒<br />");document.write("<br /><font color='#f02020'>全球标准时间:</font><br />");
document.write("UTC完整年份:"+objdate1.getUTCFullYear()+"<br />");
document.write("UTC月份:"+objdate1.getUTCMonth()+"<br />");
document.write("UTC日期:"+objdate1.getUTCDate()+"<br />");
document.write("UTC周:"+objdate1.getUTCDay()+"<br />");
document.write("UTC小时:"+objdate1.getUTCHours()+"<br />");//主要是时区差的问题
document.write("UTC分钟:"+objdate1.getUTCMinutes()+"<br />");
document.write("UTC秒钟:"+objdate1.getUTCSeconds()+"<br />");
document.write("UTC毫秒:"+objdate1.getUTCMilliseconds()+"<br />");
运行结果:
常用时间:
完整年份:2008
完整年份:1905
年份:2008
年份:5
月份:9
月份:11
日期: 15
日期:6
周:3
周:3
小时:17
小时:12
分钟:23//-------这里只显示了一个分钟值--------这里只显示了一个分钟值--------------------这里只显示了一个分钟值。
秒钟:4
秒钟:2
毫秒:437
现在距离1970年1月1日午夜已经有:1224063124.437秒全球标准时间:
UTC完整年份:2008
UTC月份:9
UTC日期:15
UTC周:3
UTC小时:9
UTC分钟:32
UTC秒钟:4
UTC毫秒:437