let date = new date(); // 獲取當前日期與時間(wed may 29 2019 10:26:52 gmt+0800 (中國標準時間))
date.getfullyear(); //獲取完整的年份(4位,2019)
date.getmonth() + 1; //獲取當前月份(1-12)
date.getdate(); //獲取當前日(1-31)
date.getday(); //獲取當前星期x(0-6,0代表星期天)
date.gettime(); //獲取當前時間(從1970.1.1開始的毫秒數)
date.gethours(); //獲取當前小時數(0-23)
date.getminutes(); //獲取當前分鐘數(0-59)
date.getseconds(); //獲取當前秒數(0-59)
date.getmilliseconds(); //獲取當前毫秒數(0-999)
date.tolocaledatestring(); //獲取當前日期(2019/5/20)
date.tolocaletimestring(); //獲取當前時間(上午10:25:20)
date.tolocalestring(); //獲取日期與時間(2019/5/20 上午10:25:20)
date.setdate() //設定date物件中月的某一天(1 ~31)
date.setfullyear() //設定date物件中的年份(四位數字)
date.setmonth() //設定date物件中月份(0 ~11)
date.settime() //設定date物件的時間
date.sethours() //設定date物件中的小時(0 ~23)
date.setminutes() //設定date物件中的分鐘(0 ~59)
date.setseconds() //設定date物件中的秒鐘(0 ~59)
date.setmilliseconds() //設定date物件中的毫秒(0 ~999)
JavaScript Date(日期)物件
日期物件用於處理日期和時間。date 物件用於處理日期和時間。var mydate newdate 注釋 date 物件自動使用當前的日期和時間作為其初始值。通過使用針對日期物件的方法,我們可以很容易地對日期進行操作。在下面的例子中,我們為日期物件設定了乙個特定的日期 2008 年 8 月 9 日 ...
JavaScript Date 物件方法總結
常用 date 類方法var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 31...
JavaScript Date物件方法詳細總結
方法 描述date 返回當日的日期和時間。getdate 從 date 物件返回乙個月中的某一天 1 31 getday 從 date 物件返回一周中的某一天 0 6 getmonth 從 date 物件返回月份 0 11 getfullyear 從 date 物件以四位數字返回年份。getyear...