javascript的時間函式

2021-04-14 08:55:21 字數 691 閱讀 2247

var mydate = new date();

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

mydate.getfullyear(); //獲取完整的年份(4位,1970-????)

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

mydate.getdate(); //獲取當前日(1-31)

mydate.getday(); //獲取當前星期x(0-6,0代表星期天)

mydate.gettime(); //獲取當前時間(從1970.1.1開始的毫秒數)

mydate.gethours(); //獲取當前小時數(0-23)

mydate.getminutes(); //獲取當前分鐘數(0-59)

mydate.getseconds(); //獲取當前秒數(0-59)

mydate.getmilliseconds(); //獲取當前毫秒數(0-999)

mydate.tolocaledatestring(); //獲取當前日期

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

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

mydate.setdate(day)//day 的值為1-31;設定今天為day;

JavaScript時間函式

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

JavaScript時間的處理

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

JavaScript擷取時間

最近遇到了發票列印當前時間的問題,js自帶的函式就可以獲取當前時間。可以用 date 方法獲得當日的日期 date 物件自動使用當前的日期和時間作為其初始值。mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位 1970 mydate.getm...