首页 > 其他 > 详细

根据日期取得此日期是本年的第几周并获取本周的开始、结束时间

时间:2015-11-12 21:29:19      阅读:262      评论:0      收藏:0      [点我收藏+]

function weekOfYearDay(time) {
var time=time;
time = time.substring(0,4)+"-"+time.substring(4,6)+"-"+time.substring(6,8);
oToday = new Date(time);
currentDay = oToday.getDay();
if (currentDay == 0) { currentDay = 7 }
mondayTime = oToday.getTime() - (currentDay - 1) * 24 * 60 * 60 * 1000;
sundayTime = oToday.getTime() + (7 - currentDay) * 24 * 60 * 60 * 1000;
var monday = new Date(mondayTime).toLocaleDateString();
var month = monday.substring(5,7) >= 10 ? monday.substring(5,7) : "0" + monday.substring(5,7);
var day = monday.substring(8,10) >= 10 ? monday.substring(8,10)+"" : "0"+monday.substring(8,10);
monday = monday.substring(0,4)+month+day;
var sunday = new Date(sundayTime).toLocaleDateString();
var s_month = sunday.substring(5,7) >= 10 ? sunday.substring(5,7) : "0" + sunday.substring(5,7);
var s_day = sunday.substring(8,10) >= 10 ? sunday.substring(8,10)+"" : "0"+sunday.substring(8,10);
sunday = sunday.substring(0,4)+s_month+s_day;
sunday = s_month+s_day;
return monday + "~" + sunday;
}

//获取某年某周的开始日期
function getBeginDateOfWeek(paraYear, weekIndex){
var firstDay = GetFirstWeekBegDay(paraYear);
//7*24*3600000 是一星期的时间毫秒数,(JS中的日期精确到毫秒)
var time=(weekIndex-1)*7*24*3600000;
var beginDay = firstDay;
//为日期对象 date 重新设置成时间 time
beginDay.setTime(firstDay.valueOf()+time);
return formatDate(beginDay);
}

//获取某年某周的结束日期
function getEndDateOfWeek(paraYear, weekIndex){
var firstDay = GetFirstWeekBegDay(paraYear);
//7*24*3600000 是一星期的时间毫秒数,(JS中的日期精确到毫秒)
var time=(weekIndex-1)*7*24*3600000;
var weekTime = 6*24*3600000;
var endDay = firstDay;
//为日期对象 date 重新设置成时间 time
endDay.setTime(firstDay.valueOf()+weekTime+time);
return formatDate(endDay);
}

根据日期取得此日期是本年的第几周并获取本周的开始、结束时间

原文:http://www.cnblogs.com/gj-persist/p/4960065.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!