js 時間處理

2022-08-09 20:09:11 字數 630 閱讀 2257

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( ); //獲取日期與時間

js時間相關處理

方法定義 gettime 方法可返回距 1970 年 1 月 1 日之間的毫秒數。通常我們計算時間差都是通過獲取兩個時間資料,然後分別使用gettime 方法返回與固定的1970 年 1 月 1 日的時間差,通過對返回毫秒數的差,換算成時間單位,得出兩個時間的時間差。首先你會有一串初始的時間資料,然...

js 時間處理方法

var format function time var time1 format new date function formattime time 簡化寫法 var format function time var time1 format new date date的 tojson 方法返回格...

js 時間戳簡單處理

js 時間戳簡單處理 時間戳字串轉時間格式字串 var time new date rowdata.starttime value time.tolocalestring 時間字串轉時間戳 var star new date rowdata.starttime starttime star.gett...