js筆記:數學物件+日期+定時器
getFullYear() 年
getMonth() 月 d.getMonth()+1 月份從0開始
getDate() 日期 從 Date 物件返回一週中的某一天 (0 ~ 6)。
getHours() 返回 Date 物件的小時 (0 ~ 23)。
getMinutes() 返回 Date 物件的分鐘 (0 ~ 59)。
getSeconds() 返回 Date 物件的秒數 (0 ~ 59)。
getTime() 返回 1970 年 1 月 1 日至今的毫秒數。
Date.parse() 返回1970年1月1日午夜到指定日期(字串)的毫秒數。
setDate() 設定 Date 物件中月的某一天 (1 ~ 31)。
setMonth() 設定 Date 物件中月份 (0 ~ 11)。
setFullYear() 設定 Date 物件中的年份(四位數字)。
toLocaleString() 年月日時分秒
toLocaleDateString() 年月日
var time = new Date(); //不傳參 是當前時間 Thu Jan 03 2019 14:09:27 GMT+0800 (中國標準時間)
//var time1 = new Date("2019/3/1"); //傳參 代表你傳的時間 轉為 中國標準時間
3、定時器
單位:毫秒
定時器分為:
單次定時
setTimeout(function(){
console.log(1);
},時間)
多次定時
setInterval(function(){
},時間)
如果想移除定時器,就要給定時器起個名字
clearInterval(定時器的名字);
clearTimeout(定時器的名字);