js Date物件 (個人學習筆記)

2022-04-02 00:23:50 字數 1744 閱讀 8260

date物件用於處理日期和 時間

1.直接獲取當前的時間為標準時間

var date = new date();//

wed may 30 2018 14:25:30 gmt+0800 (中國標準時間)

var date1 = new date("january 12,2006 22:19:35") // 可以傳入乙個時間 進行轉化

console.log(date1)  

//thu jan 12 2006 22:19:35 gmt+0800 (中國標準時間)

2.常用的物件方法

get方法

date.getfullyear()  //2017  從 date 物件以四位數字返回年份

date.getmonth()  //11  從 date 物件返回月份 (0 ~ 11) 需要加1才是我們正常的月份

date.getday()  //2  從 date 物件返回一周中的某一天 (0 ~ 6) 是星期幾

date.getdate()  //12  從 date 物件返回乙個月中的某一天 (1 ~ 31

date.gethours()  //23  返回 date 物件的小時 (0 ~ 23)

date.getminutes()  //30  返回 date 物件的分鐘 (0 ~ 59)

date.getseconds()  //54  返回 date 物件的秒數 (0 ~ 59)

date.getmilliseconds()  返回 date 物件的毫秒(0 ~ 999)

date.gettime()  返回 1970 年 1 月 1 日至今的毫秒數

常用場景:時間戳

set方法

setfullyear(year, opt_month, opt_date) :設定date物件的年份值;4位年份。

setmonth(month, opt_date) :設定date物件的月份值。0表示1月,11表示12月。

setdate(date) :設定date物件的月份中的日期值;值的範圍1~31 。

sethours(hour, opt_min, opt_sec, opt_msec) :設定date物件的小時值。

setminutes(min, opt_sec, opt_msec) :設定date物件的分鐘值。

setseconds(sec, opt_msec) :設定date物件的秒數值。

setmilliseconds(msec) :設定date物件的毫秒值。

其他方法

tostring() :將date轉換為乙個'年月日 時分秒'字串

tolocalestring() :將date轉換為乙個'年月日 時分秒'的本地格式字串

todatestring() :將date轉換為乙個'年月日'字串

tolocaledatestring() :將date轉換為乙個'年月日'的本地格式字串

totimestring() :將date轉換為乙個'時分秒'字串

tolocaletimestring() :將date轉換為乙個'時分秒'的本地格式字串

valueof() :與gettime()一樣, 返回date物件與'1970/01/01 00:00:00'之間的毫秒值(北京時間的時區為東8區,起點時間實際為:'1970/01/01 08:00:00')

js Math物件方法 (個人學習筆記)

方法 1.丟棄小數部分,保留整數部分 parseint 5 2 2.向上取整,有小數就整數部分加1 math.ceil 5 2 3,四捨五入.math.round 5 2 4,向下取整 math.floor 5 2 5,返回數的絕對值 math.abs x 6,返回 x 和 y 中的最高值 math...

SAP BW個人學習筆記

sap bw個人學習筆記 難免有錯,持續更新,切勿對號入座。一 kpi 1 kpi是線性遞增的 2 kpi關鍵指標 一般情況下,2個模組,就有40個kpi,3個模組,有60多個kpi 二 增強 1 只有不符合要求時,才使用增強,還要使用標準字段。三 財務資料源 財務資料源是用的後像,也即是餘像,只能...

ajax個人學習筆記

1.function createxhr else if typeof activexobject undefined catch e else 2.ie瀏覽器第一次向伺服器端請求,獲取最新資料,其後預設獲取的是快取資料,而不是最新的資料,可以使用js中的隨機字串處理。3.ajax非同步 true ...