獲取時間(本週,上週,本月,上月)

2021-08-21 15:03:48 字數 858 閱讀 2118

首先此處使用的是moment.js

用法:一、node用法

npm install moment
然後引入需要用的地方

官方給出如下

var moment = require('moment')
我在react裡面引用如下:

import moment from 'moment';
原理一致,只是不同框架匯入方式不一樣,匯入即可使用

1.本週

starts = moment().startof('week');//周一 

ends =moment().endof('week');//週日

2.上週

starts = moment().startof('week').subtract('week',1);

ends = moment().endof('week').subtract('week', 1);

3.本月

starts = moment().startof('month');

ends = moment().endof('month').endof('month');

4.上月

starts = moment().startof('month').subtract('month',1);

ends = moment().endof('month').subtract('month',1).endof('month');

參考moment.js

sql時間查詢上週 本週 上月 本月

如何實現只顯示本月資訊 sql select from table where datediff m,date,now 0 sql 查詢本週本月 求相差天數 select datediff day,2004 01 01 getdate 1.乙個月第一天的 select dateadd mm,date...

整理獲取本週本月本年上週上月的時間區間的方法

獲取上週的開始時間和結束時間 numberutil.getlong starttime dateutil.yyyy mm dd return public static mapgetlastweek 獲取上月的開始時間和結束時間 numberutil.getlong starttime dateut...

PHP本週 上週 本月 上月 去年 今年的時間戳

注意 網上大多數計算周的時候使用php4.1的date w 0 6這樣會導致週日0計算有誤,所以需要做個判斷,週日的時候使用php5.1版本以後的1 7的 date n 本週時間戳if date w 0 else 上週時間戳if date w 0 else 上上週時間戳if date w 0 els...