js Date對象的使用

獲取當前時間 ,用spa

var now = new Date(); //獲取當前時間,Tue Feb 07 2017 17:28:35 GMT+0800 (中國標準時間)code

now.getFullYear(); //2017,年份對象

now.getMonth(); //1,月份的範圍是0-11,1是表示2月份blog

now.getDate(); //07,日get

now.getDay(); //2,星期二class

now.getHours(); //17,小時,24小時制date

now.getMinutes(); //28,分鐘im

now.getSeconds(); //35,秒時間戳

now.getMilliseconds(); //774,毫秒di

now.getTime(); //1486459715774,獲取時間戳

情人節想和女票出去吃一頓。。。。。

var now = new Date();
var time = now.getTime();
var year = now.getFullYear();
var month = now.getMonth();
var date = now.getDate();
var day = now.getDay();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var milliseconds = now.getMilliseconds();
if (month===1&&date===14) { //情人節是幾月幾號來着...
    alert('小妞,出來吧,我在餐廳定了位!');
}else {
    alert('天天都是情人節,咱們就在家吃吧!');
}


咱們也能夠建立一個指定日期時間的對象

var date = new Date(2017,1,07,17,28,35,774);//對應 年、月(二月)、日、小時、分、秒、微秒

相關文章
相關標籤/搜索