js Date物件的使用

2022-08-17 01:54:08 字數 972 閱讀 3365

獲取當前時間 ,用

var now = new date(); //獲取當前時間,tue feb 07 2017 17:28:35 gmt+0800 (中國標準時間)

now.getfullyear(); //2017,年份

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

now.getdate(); //07,日

now.getday(); //2,星期二

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

now.getminutes(); //28,分鐘

now.getseconds(); //35,秒

now.getmilliseconds(); //774,毫秒

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)

else

我們也可以建立乙個指定日期時間的物件

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

js Date時間物件

date時間物件 var today new date 獲取當前日期時間,返回乙個日期物件 var birth new date 1995 12 03 23 18 34 出生日期 var time today.gettime 獲取today變數時間的毫秒數 gettime 時間戳,用於唯一標誌 to...

JS DATE物件詳解

獲取時間物件 newdate 獲取年份 getfullyear 獲取月份 getmonth 獲取星期 getdate 獲取日 getday 獲取小時 gethours 獲取分鐘 getminutes 獲取秒 getseconds 時間轉換公式 天 math.floor t 86400 時 math....

JS DATE物件詳解

1 建立時間物件 可獲取年,月,日,星期,時,分,秒 var d new date console.log d.getfullyear 年 d.getmonth 月 d.getdate 星期 d.getday 日 d.gethours 小時 d.getminutes 分 d.getseconds 秒...