日期:2014-05-16  浏览次数:20409 次

JS获取本周、本季度、本月、上月的开始日期、结束日期
Js代码 复制代码
  1. /**
  2. * 获取本周、本季度、本月、上月的开始日期、结束日期
  3. */
  4. var now = new Date(); //当前日期
  5. var nowDayOfWeek = now.getDay(); //今天本周的第几天
  6. var nowDay = now.getDate(); //当前日
  7. var nowMonth = now.getMonth(); //当前月
  8. var nowYear = now.getYear(); //当前年
  9. nowYear += (nowYear < 2000) ? 1900 : 0; //
  10. var lastMonthDate = new Date(); //上月日期
  11. lastMonthDate.setDate(1);
  12. lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
  13. var lastYear = lastMonthDate.getYear();
  14. var lastMonth = lastMonthDate.getMonth();
  15. //格式化日期:yyyy-MM-dd
  16. function formatDate(date) {
  17. var myyear = date.getFullYear();
  18. var mymonth = date.getMonth()+1;
  19. var myweekday = date.getDate();
  20. if(mymonth < 10){
  21. mymonth = "0" + mymonth;
  22. }
  23. if(myweekday < 10){
  24. myweekday = "0" + myweekday;
  25. }
  26. return (myyear+