js的dataTime操作方法

2021-08-03 15:39:15 字數 814 閱讀 4079

js的datatime操作方法

web開發中經常對時間進行處理操作,例如比較時間大小,

時間的間隔,字串與時間之間的轉化等等。

如何將字串轉時間物件。

var s = "2005-12-15 09:41:30";

var d = new date(date.parse(s.replace(/-/g, "/")));

date常用的api:

var mydate = new date();

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

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

var moonth=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)

var mytime=mydate.tolocaledatestring(); //獲取當前日期 //怎麼是英文的

JS操作方法

一 map函式 可以接受函式作為引數 var staff staff.map function item 執行結果 abruzzi bajmine chris 二 filter函式 過濾陣列中滿足某些條件的元素 staff.filter function item 執行結果 name bajmine...

js 物件操作方法

1.object.assign object.assign 方法用於將所有可列舉屬性的值從乙個或多個源物件複製到目標物件。它將返回目標物件。const object1 const object2 object.assign object1 console.log object2.c,object2....

JS陣列的操作方法

var colors red blue green colors.length 計算陣列長度 array.isarray colors 檢測是否為陣列 colors.join 指定引號內的字串為分隔符 colors.push red green 推入陣列的最後 colors.pop 取得陣列的最後項...