JS獲取當前日期時間

2021-08-07 18:14:13 字數 811 閱讀 5600

var mydate = new

date();

var years = mydate.getfullyear(); //從date 物件以四位數字返回年份

var months = mydate.getmonth(); //從date 物件返回月份 (0 ~ 11)

var days = mydate.getdate(); //從date物件返回乙個月中的某一(1~31)

var weekdays = mydate.getday();//從date物件返回一周中的某一天 (0~ 6)

var hours = mydate.gethours(); //返回 date 物件的小時 (0 ~ 23)。

var minutes = mydate.getminutes();//返回 date 物件的分鐘 (0 ~ 59)。

var seconds = mydate.getseconds();//返回 date 物件的秒數(0 ~ 59)。

var milliseconds = mydate.getmilliseconds(); //返回date物件的毫秒(0~999)。

var gettime = mydate.gettime(); //返回 1970 年 1 月 1 日至今的毫秒數。

嗯,就是單純的想記下來,以後用到就可以直接copy啦,還有,真心覺得jquery實在不要太好用哇~

html :

id="time">div> js

setinterval(function

(),1000);

Js獲取當前日期時間

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

Js獲取當前日期時間

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

js獲取當前日期時間

function getnowformatdate if strdate 0 strdate 9 var currentdate year seperator1 month seperator1 strdate return currentdate 呼叫直接獲取當天日期 獲取當前日期時間 funct...