js 時間處理相關方法

2021-10-06 20:39:12 字數 2447 閱讀 2055

/**

* 獲取本週、本季度、本月、上月的開端日期、停止日期

*/var now = new date(); //當前日期

var nowdayofweek = now.getday(); //今天本週的第幾天

var nowday = now.getdate(); //當前日

var nowmonth = now.getmonth(); //當前月

var nowyear = now.getyear(); //當前年

nowyear += (nowyear < 2000) ? 1900 : 0; //

var lastmonthdate = new date(); //上月日期

lastmonthdate.setdate(1);

lastmonthdate.setmonth(lastmonthdate.getmonth()-1);

var lastyear = lastmonthdate.getyear();

var lastmonth = lastmonthdate.getmonth();

export const endquartermap=

export const beginquartermap=

//格局化日期:yyyy-mm-dd

export function formatdate(date)

if(myweekday < 10)

return (myyear+"-"+mymonth + "-" + myweekday);

}//獲得某月的天數

export function getmonthdays(mymonth)

//獲得本季度的開端月份

export function getquarterstartmonth()

if(28)

return quarterstartmonth;

}//獲得本週的開端日期

export function getweekstartdate()

//獲得本週的停止日期

export function getweekenddate()

//獲得本月的開端日期

export function getmonthstartdate()

//獲得本月的停止日期

export function getmonthenddate()

//獲得上月開端時候

export function getlastmonthstartdate()

//獲得上月停止時候

export function getlastmonthenddate()

//獲得本季度的開端日期

export function getquarterstartdate()

//或的本季度的停止日期

export function getquarterenddate()

export function getcurrentquarternum(month=nowmonth)

if(39)

return quarterstartmonth

}//獲取當前季度

export function getcurrentquarter(ndate=new date())

// 獲取上一季度

export function getlastquarter()else

}// 獲取間隔季度日期

export function getdifquarter(dif=-1,nquarter=getcurrentquarter())else

}// 獲取間隔天數日期

export function getdifdate(dif=-1,ndate=new date())

//獲取間隔月數日期

export function getdifmonth(dif=-1,ndate=new date())

// 獲取間隔年數日期

export function getdifyear(dif=-1,ndate=new date())

//獲取當前月份

export function getcurrentmonth()

方法列表:

1、格局化日期:yyyy-mm-dd

2、獲得某月的天數

3、獲得本季度的開端月份

4、獲得本週的開端日期

5、獲得本週的停止日期

6、獲得本月的開端日期

7、獲得本月的停止日期

8、獲得上月開端時候

9、獲得上月停止時候

10、獲得本季度的開端日期

11、獲得本季度的停止日期

12、獲取當前季度

13、獲取上一季度

14、獲取間隔季度日期

15、獲取間隔天數日期

16、獲取間隔月數日期

17、獲取間隔年數日期

18、獲取當前月份

js時間相關處理

方法定義 gettime 方法可返回距 1970 年 1 月 1 日之間的毫秒數。通常我們計算時間差都是通過獲取兩個時間資料,然後分別使用gettime 方法返回與固定的1970 年 1 月 1 日的時間差,通過對返回毫秒數的差,換算成時間單位,得出兩個時間的時間差。首先你會有一串初始的時間資料,然...

js 時間處理方法

var format function time var time1 format new date function formattime time 簡化寫法 var format function time var time1 format new date date的 tojson 方法返回格...

時間相關的js方法

function getdatestr1 function getdatestr2 function ww4 date function w4 s else function myformatter date function myparser s else function todate str ...