JS DATE物件詳解

2022-09-02 07:36:12 字數 657 閱讀 6839

1、建立時間物件:可獲取年,月,日,星期,時,分,秒

var d = new date();

console.log(d.getfullyear()+'年'+d.getmonth()+'月'+d.getdate()+'星期'+d.getday()+'日'+d.gethours()+'小時'+d.getminutes()+'分'+d.getseconds()+'秒');

2、獲取時間戳

console.log(d.gettime());

3、時間轉換公式

math.floor(t/86400) //天

math.floor(t%86400/3600) //時

math.floor(t%86400%3600/60) //分

t%60 //秒

4、js格式化日期

var format = function(time, format);

return format.replace(/yyyy|mm|dd|hh|mm|ss/g, function(a)

})}format(new date().gettime(), 'yyyy-mm-dd hh:mm:ss')//gettime返回距 1970 年 1 月 1 日之間的毫秒數

JS DATE物件詳解

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

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 使用詳解

js date 使用詳解 var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 ...