您好我想问一下,我怎样才能在Javascript或Javascript库中进行Moment.js http://momentjs.com/docs/(我更喜欢这个库)以下内容:
Today is date (for example): 18-09-2014
我需要从给定的日期获得实际周的范围(从星期一到星期日),这意味着 给定日期我应该得到结果:
start: 15-09-2014
end: 21-09-2014
有可能,我该怎么做?
感谢您的帮助。
答案 0 :(得分:6)
我想:
moment().day(1); // Monday
moment().day(7); // Sunday
答案 1 :(得分:-1)
<script>
Date.prototype.getWeek = function(start)
{
// the starting point
start = start || 0;
var today = new Date(this.setHours(0, 0, 0, 0));
var day = today.getDay() - start;
var date = today.getDate() - day;
// Start/End Dates
var StartDate = new Date(today.setDate(date));
var EndDate = new Date(today.setDate(date + 6));
return [StartDate, EndDate];
}
// test code
var Dates = new Date().getWeek();
alert(Dates[0].toLocaleDateString() + ' to '+ Dates[1].toLocaleDateString())
</script>