js獲取時間 日期相關方法

2021-10-01 03:28:56 字數 603 閱讀 8883

var date = new date();

date .getyear(); //獲取當前年份(2位)

date .getfullyear(); //獲取完整的年份(4位)

date .getmonth(); //獲取當前月份(0-11,0代表1月)

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(); //獲取當前日期

var mytime=date .tolocaletimestring(); //獲取當前時間

date .tolocalestring( ); //獲取日期與時間

JS獲取當前時間日期

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

時間日期相關

yyyy mm dd hh mm ss 代表將時間轉換為24小時制,如2019 05 25 15 24 21 yyyy mm dd hh mm ss 代表將時間轉換為12小時制,如2019 05 25 03 24 21 餓了麼時間控制項,新增屬性更改格式 value format yyyy mm d...

JS獲取當前時間 日期補0位

建立補0函式 functionp s var clock year if month 10 clock 0 clock month if day 10 clock 0 clock day if hh 10 clock 0 clock hh if mm 10 clock 0 clock mm retu...