js Date時間物件

2021-09-25 12:14:13 字數 1186 閱讀 1586

date時間物件

var today = new date(); // 獲取當前日期時間,返回乙個日期物件

var birth = new date('1995-12-03 23:18:34');  // 出生日期

var time = today.gettime();  //  獲取today變數時間的毫秒數;gettime()時間戳,用於唯一標誌

today.getyear();  // 返回當前年份距離2023年的年份差

today.getfullyear();  // 獲取四位年份

today.getmonth();  //  獲取月份,計算機的月份從0開始計算

today.getdate();  //  獲取日

today.getday();  //  獲取週幾

today.gethours();  //  獲取時

today.getminutes();  //  獲取分

today.getsecond();  //  獲取秒

today.getmillisecond();  //  獲取毫秒

today.setfullyear(2019):設定年份

today.setyear(n):設定年份,若n超過兩位數,返回引數n;n為1位數或1位數,則返回(1900 + n)

today.setmonth(n):n為月份引數,返回的月份為n + 1;

today.setdate(n):設定日期

today.sethours(n):設定小時

today.setminutes(n):設定分鐘

today.setsecond(n):設定秒數

無法設定週幾,此值由年月日推算而來

獲取日期物件字串

today.todatestring(); // 只返回年月日(日期),國際化日期格式

today.tolocaledatestring();  //  只返回年月日(日期),中國標準日期格式

today.totimesstring();  //  只返回時分秒(時間),國際化日期格式

today.tolocaletimesstring();  //  只返回時分秒(時間),中國標準時間格式

today.tostring();  //  返回日期+時間,國際化日期格式

today.tolocalestring();  //  返回日期+時間,中國標準時間格式

js Date 物件用於處理日期和時間。

date 物件用於處理日期和時間。建立 date 物件的語法 var mydate new date date 物件會自動把當前日期和時間儲存為其初始值。引數形式有以下 種 new date month dd,yyyy hh mm ss new date month dd,yyyy new date...

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 秒...