Js獲取或計算時間的相關操作

2021-08-28 15:32:54 字數 601 閱讀 3869

1     //獲取當前日期(年月日),如:2017-12-18

2 function getnowdate()

11 12 //計算多少天前後的日期

13 //adddaycount:前後要計算的天數

14 //startdate:開始日期,為空則表示當前日期

15 function getdateadd(adddaycount, startdate)

39 40 /**

41 * 計算2個日期相差的天數,可包含今天,如:2017-12-18到2017-12-20,相差2天(isincludetoday=true時為3天)

42 * startdatestring:開始日期

43 * enddatestring:結束日期

44 * isincludetoday:是否包含今天

45 */

46 function datediff(startdatestring, enddatestring, isincludetoday)

js 獲取時間相關

let date new date date.getyear 獲取當前年份 2位 date.getfullyear 獲取完整的年份 4位 date.getmonth 獲取當前月份 0 11,0代表1月 date.getdate 獲取當前日 1 31 date.getday 獲取當前星期x 0 6,0...

js計算時間系列操作

let starttime new date var mydate newdate 獲取當前系統時間 建立乙個物件 獲取到的時間為 wed jun 03 202017 24 55 gmt 0800 中國標準時間 var mydate newdate 2010 10 09 獲取指定時間物件 建立乙個物...

js對當前時間的相關操作

js中獲得當前時間是年份和月份,形如 201208 獲取完整的日期 var date new date var year date.getfullyear var month date.getmonth 1 month month 10 0 month month var mydate year.t...