4 js之Date

2018-06-01  本文已影响0人  一枝妖孽
//当前日期
document.write(Date())
//getTime()
var d=new Date();
document.write("从 1970/01/01 至今已过去 " + d.getTime() + " 毫秒");
//setFullYear
var d = new Date()
d.setFullYear(1992,10,3)
document.write(d)
//toUTCString()
var d = new Date()
document.write (d.toUTCString())

//getDay()
var d=new Date()
var weekday=new Array(7)
weekday[0]="星期日"
weekday[1]="星期一"
weekday[2]="星期二"
weekday[3]="星期三"
weekday[4]="星期四"
weekday[5]="星期五"
weekday[6]="星期六"

document.write("今天是" + weekday[d.getDay()])

比较日期

var myDate=new Date();
myDate.setFullYear(2008,8,9);
var today = new Date();
if (myDate>today)
{
alert("Today is before 9th August 2008");
}
else
{
alert("Today is after 9th August 2008");
}
上一篇 下一篇

猜你喜欢

热点阅读