下周使用jquery和moment js开始和结束 [英] get next week start and end using jquery and moment js
本文介绍了下周使用jquery和moment js开始和结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了这个问题,发现Stackoverflow上没有答案。所以我决定回答它...
I searched for this question and found there is a no answer on Stackoverflow.. So I decided to answer it...
如果你需要,这个问题会有所帮助以周一作为周开始获得下一周/上周的开始/结束。
This question helps if you need to get the start/end of next/last week with Monday as start of week.
推荐答案
我使用了瞬间js ...你可以从这里
I used moment js for this ... u can get it from here
/*
all functions return moment() object.. <br>
GetNextWeekStart().format('DD/MM/YYYY') to get 24/02/2014
*/
function GetNextWeekStart() {
var today = moment();
//edited part
var daystoMonday = 0 - (today.isoWeekday() - 1) + 7;
var nextMonday = today.subtract('days', daystoMonday);
return nextMonday;
}
function GetNextWeekEnd() {
var nextMonday = GetNextWeekStart();
var nextSunday = nextMonday.add('days', 6);
return nextSunday;
}
function GetLastWeekStart() {
var today = moment();
var daystoLastMonday = 0 - (1 - today.isoWeekday()) + 7;
var lastMonday = today.subtract('days', daystoLastMonday);
return lastMonday;
}
function GetLastWeekEnd() {
var lastMonday = GetLastWeekStart();
var lastSunday = lastMonday.add('days', 6);
return lastSunday;
}
这篇关于下周使用jquery和moment js开始和结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文