js如何获取到本周的第一天和最后一天,本月的第一天和最后一天以及本季度的第一天和最后一天

时间:2023-03-09 07:08:22
js如何获取到本周的第一天和最后一天,本月的第一天和最后一天以及本季度的第一天和最后一天

1、首先来一个自己公司项目的源码:

项目需求描述: 从20150712日开始, ,

需求①:根据当前时间返回每一周 、周一~周日的日期(需返回2种格式 格式1:7月13日,格式2:2015-07-13)

需求②:返回当前时间本周的,周一早上9:00:00和周日的23:59:59

需求③:计算出当前时间离20150712日有多少周

需求④:在需求3基础上,如果大于一周,需要返回历史周的周一早上9:00:00和周日的23:59:59  (在此用二位数组)

  1. function GetWeekDate(time){
  2. var now = new Date(time); //当前日期
  3. this.nowDayOfWeek = now.getDay(); //今天本周的第几天
  4. this.nowYear = now.getYear(); //当前年
  5. this.nowMonth = now.getMonth(); //月
  6. this.nowDay = now.getDate(); //日
  7. this.beginHour="09:00:00";
  8. this.endHour="23:59:59";
  9. this.nowYear += (this.nowYear < 2000) ? 1900 : 0; //
  10. this.nowDayOfWeek = this.nowDayOfWeek==0?7:this.nowDayOfWeek; // 如果是周日,就变成周七
  11. }
  12. GetWeekDate.prototype.date2str=function(x,y){//date2str(new Date(curTime),"yyyy-MM-dd")
  13. var z ={y:x.getFullYear(),M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()};
  14. return y.replace(/(y+|M+|d+|h+|m+|s+)/g,function(v) {return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-(v.length>2?v.length:2))});
  15. }
  16. GetWeekDate.prototype.formatDate=function(date){//格局化日期:yyyy-MM-dd
  17. var myyear = date.getFullYear();
  18. var mymonth = date.getMonth()+1;
  19. var myweekday = date.getDate();
  20. //alert("formatDate"+myyear+":"+mymonth+":"+myweekday)
  21. if(mymonth < 10){
  22. mymonth = "0" + mymonth;
  23. }
  24. if(myweekday < 10){
  25. myweekday = "0" + myweekday;
  26. }
  27. return (myyear+"-"+mymonth + "-" + myweekday);
  28. }
  29. GetWeekDate.prototype.getWeekStartDate=function(){ //获得本周的开端日期
  30. var weekStartDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek+1);
  31. return this.formatDate(weekStartDate);
  32. }
  33. GetWeekDate.prototype.getWeekEndDate=function(){//获得本周的停止日期
  34. var weekEndDate = new Date(this.nowYear, this.nowMonth, this.nowDay + (6 - this.nowDayOfWeek+1));
  35. return this.formatDate(weekEndDate);
  36. }
  37. GetWeekDate.prototype.getAWeedkYMD=function(){//获得本周周一~周日的年月日
  38. var ymdArr=[];
  39. for (var i = 0; i < 7; i++) {
  40. ymdArr[i]=[];
  41. //ymdArr[i][0]=this.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek+i+1));
  42. ymdArr[i][0]=this.date2str(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek+i+1),'yyyy-MM-dd');
  43. ymdArr[i][1]=this.date2str(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek+i+1), 'MM月dd日');
  44. };
  45. return ymdArr;
  46. }
  47. GetWeekDate.prototype.getQishu=function(time){//获得本周是指定日期(7.12日)的第几周
  48. var oNDate=new Date(time); //系统当前时间
  49. var oEDate=new Date('2015/7/12 23:59:59');
  50. var diff= oNDate.getTime()-oEDate.getTime();
  51. //console.log(diff)
  52. //console.log("相差天:"+diff/(24*60*60*1000))
  53. //console.log("相差期数:"+parseInt(diff/(24*60*60*1000))/7)
  54. //console.log("取整期数:"+Math.floor(parseInt(diff/(24*60*60*1000))/7))
  55. return (diff/(24*60*60*1000))/7;
  56. }
  57. GetWeekDate.prototype.getWeeksDates=function(time){//获取历史周排行的周一到周日时间段
  58. var qishu = (this.qishu || this.qishu==0)?this.qishu:this.getQishu(time);
  59. //var qishu=this.getQishu(time);
  60. var WeeksTimes=[];//存放时间的二维数组
  61. minYear=2015,
  62. minMonth=7,
  63. minDay=12;
  64. for (var i = 0; i<qishu; i++) {
  65. var sday;
  66. var eday;
  67. WeeksTimes[i]=[];
  68. if(i==0){//如果离2015-07-12只相差1期
  69. sday=minDay+1; //开始时间+1天
  70. }else{//如果离2015-07-12相差期数>1
  71. sday=minDay+1+7*i;
  72. }
  73. eday=minDay+7*(i+1);//结束时间+7天
  74. WeeksTimes[i][0]=this.formatDate(new Date(minYear,minMonth-1,sday))+" "+this.beginHour;
  75. WeeksTimes[i][1]=this.formatDate(new Date(minYear,minMonth-1,eday))+" "+this.endHour;
  76. };
  77. //如果是一周的周日就不要减去一期
  78. return WeeksTimes;
  79. }
  80. GetWeekDate.prototype.todayData=function(json){//处理tender_list_week.jsp页面
  81. var oQishu=$('.qishu');
  82. iQishu=this.qishu;//期数+1是因为,相差0期就是第1期
  83. oThisWeekListBtn=$('.total_list_btn'),//查看本周排行榜按钮
  84. sTime=this.getWeekStartDate()+" "+this.beginHour,
  85. eTime=this.getWeekEndDate()+" "+this.endHour;
  86. //1、修改期数
  87. //console.log("相差周:"+iQishu);
  88. if(/^[1-9]\d*$/.test(iQishu) || iQishu==0){//整数 +3
  89. oQishu.html(iQishu*1+3);
  90. }else{
  91. oQishu.html(Math.floor(iQishu)*1+4);
  92. }
  93. oThisWeekListBtn.attr("onclick","showWeekList('"+sTime+"','"+eTime+"')");//2、修改查看本周排行榜的起止时间
  94. }
  95. GetWeekDate.prototype.historyData=function(time){//处理tender_list_week.jsp页面
  96. var oQishu=$('.qishu'),
  97. oDateList=$('#dateList'), //顶部导航时间
  98. oHistoryList=$('#history_cont'),//历史周
  99. aThisWeekYMD=this.getAWeedkYMD(),//本周周一~周日的年月日
  100. aThisWeekDates=this.getWeeksDates(time);//获取历史周排行的周一到周日时间段
  101. iQishu=this.qishu;
  102. //console.log("相差周:"+iQishu);
  103. //1、修改期数,+4是加上前3期,在+1是如果间隔3期,当前就是第4期
  104. //如果时间23:59:59是正整数(-1),如果是0整数(3),如果是非整数(向下取整),或负数(向上取整)但是负数不考虑
  105. //oQishu.html(iQishu*1+3);
  106. if(/^[1-9]\d*$/.test(iQishu) || iQishu==0){//整数 +3
  107. oQishu.html(iQishu*1+3);
  108. }else{
  109. oQishu.html(Math.floor(iQishu)*1+4);
  110. }
  111. //2、给顶部时间追加时间
  112. for (var i = 0; i < aThisWeekYMD.length; i++) {
  113. var str='<li data-time="'+aThisWeekYMD[i][0]+'">'+aThisWeekYMD[i][1]+'</li>';
  114. $(str).appendTo(oDateList);
  115. };
  116. //3、给历史周排行榜添加周期数
  117. if(this.qishu>1){//如果相差的期数大于1期
  118. //console.dir(aThisWeekDates)
  119. for (var j = 0; j < aThisWeekDates.length-1; j++) {
  120. var iQiNum=j+4;
  121. var str='<li onclick="showWeekList(\''+aThisWeekDates[j][0]+'\',\''+aThisWeekDates[j][1]+'\')">第'+iQiNum+'期</li>';
  122. $(str).prependTo(oHistoryList);
  123. };
  124. }
  125. }
  126. GetWeekDate.prototype.init=function(time){
  127. var iQishu=this.getQishu(time),//期数+1是因为,相差0期就是第1期
  128. json={};
  129. json.qishu=iQishu;
  130. this.qishu=iQishu;
  131. if($('#pageType').val()=="today"){//如果是tender_list_week.jsp页面
  132. if(new Date(time).getTime() < new Date('2015/07/12 23:59:59').getTime()){//特殊处理时间小于20150712
  133. $('.qishu').html('3');
  134. $('.total_list_btn').attr("onclick","showWeekList('2015-07-03 09:00:00','2015-07-12 23:59:59')");
  135. return false;
  136. }
  137. this.todayData(json);
  138. }else if($('#pageType').val()=="history"){
  139. if(new Date(time).getTime() < new Date('2015/07/12 23:59:59').getTime()){//特殊处理时间小于20150712
  140. $('.qishu').html('3');
  141. $('#dateList').addClass('dateList2').html('<li data-time="2015-07-03">07月03日</li><li data-time="2015-07-04">07月04日</li><li data-time="2015-07-05">07月05日</li><li data-time="2015-07-06">07月06日</li><li data-time="2015-07-07">07月07日</li><li data-time="2015-07-08">07月08日</li><li data-time="2015-07-09">07月09日</li><li data-time="2015-07-10">07月10日</li><li data-time="2015-07-11">07月11日</li><li data-time="2015-07-12">07月12日</li>');
  142. $('#history_cont').html('<li onclick="showWeekList(\'2015-06-26 09:00:00\',\'2015-07-02 23:59:59\')">第二期</li><li onclick="showWeekList(\'2015-06-19 12:00:00\',\'2015-06-25 23:59:59\')">第一期</li>');
  143. return false;
  144. }
  145. this.historyData(time);
  146. }
  147. //console.dir(this.getWeeksDates(time));
  148. };

2、JS获取本周、本季度、本月、上月的开端日期、停止日期

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Document</title>
  6. <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
  7. <script>
  8. /**
  9. * 日期范围工具类
  10. */
  11. var dateRangeUtil = (function () {
  12. /***
  13. * 获得当前时间
  14. */
  15. this.getCurrentDate = function () {
  16. return new Date('2015','07','-1');
  17. };
  18. /***
  19. * 获得本周起止时间
  20. */
  21. this.getCurrentWeek = function () {
  22. //起止日期数组
  23. var startStop = new Array();
  24. //获取当前时间
  25. var currentDate = this.getCurrentDate();
  26. //返回date是一周中的某一天
  27. var week = currentDate.getDay();
  28. //返回date是一个月中的某一天
  29. var month = currentDate.getDate();
  30. //一天的毫秒数
  31. var millisecond = 1000 * 60 * 60 * 24;
  32. //减去的天数
  33. var minusDay = week != 0 ? week - 1 : 6;
  34. //alert(minusDay);
  35. //本周 周一
  36. var monday = new Date(currentDate.getTime() - (minusDay * millisecond));
  37. //本周 周日
  38. var sunday = new Date(monday.getTime() + (6 * millisecond));
  39. //添加本周时间
  40. startStop.push(monday); //本周起始时间
  41. //添加本周最后一天时间
  42. startStop.push(sunday); //本周终止时间
  43. //返回
  44. return startStop;
  45. };
  46. /***
  47. * 获得本月的起止时间
  48. */
  49. this.getCurrentMonth = function () {
  50. //起止日期数组
  51. var startStop = new Array();
  52. //获取当前时间
  53. var currentDate = this.getCurrentDate();
  54. //获得当前月份0-11
  55. var currentMonth = currentDate.getMonth();
  56. //获得当前年份4位年
  57. var currentYear = currentDate.getFullYear();
  58. //求出本月第一天
  59. var firstDay = new Date(currentYear, currentMonth, 1);
  60. //当为12月的时候年份需要加1
  61. //月份需要更新为0 也就是下一年的第一个月
  62. if (currentMonth == 11) {
  63. currentYear++;
  64. currentMonth = 0; //就为
  65. } else {
  66. //否则只是月份增加,以便求的下一月的第一天
  67. currentMonth++;
  68. }
  69. //一天的毫秒数
  70. var millisecond = 1000 * 60 * 60 * 24;
  71. //下月的第一天
  72. var nextMonthDayOne = new Date(currentYear, currentMonth, 1);
  73. //求出上月的最后一天
  74. var lastDay = new Date(nextMonthDayOne.getTime() - millisecond);
  75. //添加至数组中返回
  76. startStop.push(firstDay);
  77. startStop.push(lastDay);
  78. //返回
  79. return startStop;
  80. };
  81. /**
  82. * 得到本季度开始的月份
  83. * @param month 需要计算的月份
  84. ***/
  85. this.getQuarterSeasonStartMonth = function (month) {
  86. var quarterMonthStart = 0;
  87. var spring = 0; //春
  88. var summer = 3; //夏
  89. var fall = 6;   //秋
  90. var winter = 9; //冬
  91. //月份从0-11
  92. if (month < 3) {
  93. return spring;
  94. }
  95. if (month < 6) {
  96. return summer;
  97. }
  98. if (month < 9) {
  99. return fall;
  100. }
  101. return winter;
  102. };
  103. /**
  104. * 获得该月的天数
  105. * @param year年份
  106. * @param month月份
  107. * */
  108. this.getMonthDays = function (year, month) {
  109. //本月第一天 1-31
  110. var relativeDate = new Date(year, month, 1);
  111. //获得当前月份0-11
  112. var relativeMonth = relativeDate.getMonth();
  113. //获得当前年份4位年
  114. var relativeYear = relativeDate.getFullYear();
  115. //当为12月的时候年份需要加1
  116. //月份需要更新为0 也就是下一年的第一个月
  117. if (relativeMonth == 11) {
  118. relativeYear++;
  119. relativeMonth = 0;
  120. } else {
  121. //否则只是月份增加,以便求的下一月的第一天
  122. relativeMonth++;
  123. }
  124. //一天的毫秒数
  125. var millisecond = 1000 * 60 * 60 * 24;
  126. //下月的第一天
  127. var nextMonthDayOne = new Date(relativeYear, relativeMonth, 1);
  128. //返回得到上月的最后一天,也就是本月总天数
  129. return new Date(nextMonthDayOne.getTime() - millisecond).getDate();
  130. };
  131. /**
  132. * 获得本季度的起止日期
  133. */
  134. this.getCurrentSeason = function () {
  135. //起止日期数组
  136. var startStop = new Array();
  137. //获取当前时间
  138. var currentDate = this.getCurrentDate();
  139. //获得当前月份0-11
  140. var currentMonth = currentDate.getMonth();
  141. //获得当前年份4位年
  142. var currentYear = currentDate.getFullYear();
  143. //获得本季度开始月份
  144. var quarterSeasonStartMonth = this.getQuarterSeasonStartMonth(currentMonth);
  145. //获得本季度结束月份
  146. var quarterSeasonEndMonth = quarterSeasonStartMonth + 2;
  147. //获得本季度开始的日期
  148. var quarterSeasonStartDate = new Date(currentYear, quarterSeasonStartMonth, 1);
  149. //获得本季度结束的日期
  150. var quarterSeasonEndDate = new Date(currentYear, quarterSeasonEndMonth, this.getMonthDays(currentYear, quarterSeasonEndMonth));
  151. //加入数组返回
  152. startStop.push(quarterSeasonStartDate);
  153. startStop.push(quarterSeasonEndDate);
  154. //返回
  155. return startStop;
  156. };
  157. /***
  158. * 得到本年的起止日期
  159. *
  160. */
  161. this.getCurrentYear = function () {
  162. //起止日期数组
  163. var startStop = new Array();
  164. //获取当前时间
  165. var currentDate = this.getCurrentDate();
  166. //获得当前年份4位年
  167. var currentYear = currentDate.getFullYear();
  168. //本年第一天
  169. var currentYearFirstDate = new Date(currentYear, 0, 1);
  170. //本年最后一天
  171. var currentYearLastDate = new Date(currentYear, 11, 31);
  172. //添加至数组
  173. startStop.push(currentYearFirstDate);
  174. startStop.push(currentYearLastDate);
  175. //返回
  176. return startStop;
  177. };
  178. /**
  179. * 返回上一个月的第一天Date类型
  180. * @param year 年
  181. * @param month 月
  182. **/
  183. this.getPriorMonthFirstDay = function (year, month) {
  184. //年份为0代表,是本年的第一月,所以不能减
  185. if (month == 0) {
  186. month = 11; //月份为上年的最后月份
  187. year--; //年份减1
  188. return new Date(year, month, 1);
  189. }
  190. //否则,只减去月份
  191. month--;
  192. return new Date(year, month, 1); ;
  193. };
  194. /**
  195. * 获得上一月的起止日期
  196. * ***/
  197. this.getPreviousMonth = function () {
  198. //起止日期数组
  199. var startStop = new Array();
  200. //获取当前时间
  201. var currentDate = this.getCurrentDate();
  202. //获得当前月份0-11
  203. var currentMonth = currentDate.getMonth();
  204. //获得当前年份4位年
  205. var currentYear = currentDate.getFullYear();
  206. //获得上一个月的第一天
  207. var priorMonthFirstDay = this.getPriorMonthFirstDay(currentYear, currentMonth);
  208. //获得上一月的最后一天
  209. var priorMonthLastDay = new Date(priorMonthFirstDay.getFullYear(), priorMonthFirstDay.getMonth(), this.getMonthDays(priorMonthFirstDay.getFullYear(), priorMonthFirstDay.getMonth()));
  210. //添加至数组
  211. startStop.push(priorMonthFirstDay);
  212. startStop.push(priorMonthLastDay);
  213. //返回
  214. return startStop;
  215. };
  216. /**
  217. * 获得上一周的起止日期
  218. * **/
  219. this.getPreviousWeek = function () {
  220. //起止日期数组
  221. var startStop = new Array();
  222. //获取当前时间
  223. var currentDate = this.getCurrentDate();
  224. //返回date是一周中的某一天
  225. var week = currentDate.getDay();
  226. //返回date是一个月中的某一天
  227. var month = currentDate.getDate();
  228. //一天的毫秒数
  229. var millisecond = 1000 * 60 * 60 * 24;
  230. //减去的天数
  231. var minusDay = week != 0 ? week - 1 : 6;
  232. //获得当前周的第一天
  233. var currentWeekDayOne = new Date(currentDate.getTime() - (millisecond * minusDay));
  234. //上周最后一天即本周开始的前一天
  235. var priorWeekLastDay = new Date(currentWeekDayOne.getTime() - millisecond);
  236. //上周的第一天
  237. var priorWeekFirstDay = new Date(priorWeekLastDay.getTime() - (millisecond * 6));
  238. //添加至数组
  239. startStop.push(priorWeekFirstDay);
  240. startStop.push(priorWeekLastDay);
  241. return startStop;
  242. };
  243. /**
  244. * 得到上季度的起始日期
  245. * year 这个年应该是运算后得到的当前本季度的年份
  246. * month 这个应该是运算后得到的当前季度的开始月份
  247. * */
  248. this.getPriorSeasonFirstDay = function (year, month) {
  249. var quarterMonthStart = 0;
  250. var spring = 0; //春
  251. var summer = 3; //夏
  252. var fall = 6;   //秋
  253. var winter = 9; //冬
  254. //月份从0-11
  255. switch (month) {//季度的其实月份
  256. case spring:
  257. //如果是第一季度则应该到去年的冬季
  258. year--;
  259. month = winter;
  260. break;
  261. case summer:
  262. month = spring;
  263. break;
  264. case fall:
  265. month = summer;
  266. break;
  267. case winter:
  268. month = fall;
  269. break;
  270. };
  271. return new Date(year, month, 1);
  272. };
  273. /**
  274. * 得到上季度的起止日期
  275. * **/
  276. this.getPreviousSeason = function () {
  277. //起止日期数组
  278. var startStop = new Array();
  279. //获取当前时间
  280. var currentDate = this.getCurrentDate();
  281. //获得当前月份0-11
  282. var currentMonth = currentDate.getMonth();
  283. //获得当前年份4位年
  284. var currentYear = currentDate.getFullYear();
  285. //上季度的第一天
  286. var priorSeasonFirstDay = this.getPriorSeasonFirstDay(currentYear, currentMonth);
  287. //上季度的最后一天
  288. var priorSeasonLastDay = new Date(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2, this.getMonthDays(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2));
  289. //添加至数组
  290. startStop.push(priorSeasonFirstDay);
  291. startStop.push(priorSeasonLastDay);
  292. return startStop;
  293. };
  294. /**
  295. * 得到去年的起止日期
  296. * **/
  297. this.getPreviousYear = function () {
  298. //起止日期数组
  299. var startStop = new Array();
  300. //获取当前时间
  301. var currentDate = this.getCurrentDate();
  302. //获得当前年份4位年
  303. var currentYear = currentDate.getFullYear();
  304. currentYear--;
  305. var priorYearFirstDay = new Date(currentYear, 0, 1);
  306. var priorYearLastDay = new Date(currentYear, 11, 1);
  307. //添加至数组
  308. startStop.push(priorYearFirstDay);
  309. startStop.push(priorYearLastDay);
  310. return startStop;
  311. };
  312. return this;
  313. })();
  314. $(function(){
  315. $("#startDate").html( dateRangeUtil.getCurrentWeek() );
  316. })
  317. </script>
  318. </head>
  319. <body>
  320. <div id="startDate"></div>
  321. </body>
  322. </html>

3、JS获取本周、本季度、本月、上月的开端日期、停止日期

  1. Js代码
  2. /**
  3. * 获取本周、本季度、本月、上月的开端日期、停止日期
  4. */
  5. var now = new Date(); //当前日期
  6. var nowDayOfWeek = now.getDay(); //今天本周的第几天
  7. var nowDay = now.getDate(); //当前日
  8. var nowMonth = now.getMonth(); //当前月
  9. var nowYear = now.getYear(); //当前年
  10. nowYear += (nowYear < 2000) ? 1900 : 0; //
  11. var lastMonthDate = new Date(); //上月日期
  12. lastMonthDate.setDate(1);
  13. lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
  14. var lastYear = lastMonthDate.getYear();
  15. var lastMonth = lastMonthDate.getMonth();
  16. //格局化日期:yyyy-MM-dd
  17. function formatDate(date) {
  18. var myyear = date.getFullYear();
  19. var mymonth = date.getMonth()+1;
  20. var myweekday = date.getDate();
  21. if(mymonth < 10){
  22. mymonth = "0" + mymonth;
  23. }
  24. if(myweekday < 10){
  25. myweekday = "0" + myweekday;
  26. }
  27. return (myyear+"-"+mymonth + "-" + myweekday);
  28. }
  29. //获得某月的天数
  30. function getMonthDays(myMonth){
  31. var monthStartDate = new Date(nowYear, myMonth, 1);
  32. var monthEndDate = new Date(nowYear, myMonth + 1, 1);
  33. var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
  34. return days;
  35. }
  36. //获得本季度的开端月份
  37. function getQuarterStartMonth(){
  38. var quarterStartMonth = 0;
  39. if(nowMonth<3){
  40. quarterStartMonth = 0;
  41. }
  42. if(2<nowMonth && nowMonth<6){
  43. quarterStartMonth = 3;
  44. }
  45. if(5<nowMonth && nowMonth<9){
  46. quarterStartMonth = 6;
  47. }
  48. if(nowMonth>8){
  49. quarterStartMonth = 9;
  50. }
  51. return quarterStartMonth;
  52. }
  53. //获得本周的开端日期
  54. function getWeekStartDate() {
  55. var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
  56. return formatDate(weekStartDate);
  57. }
  58. //获得本周的停止日期
  59. function getWeekEndDate() {
  60. var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
  61. return formatDate(weekEndDate);
  62. }
  63. //获得本月的开端日期
  64. function getMonthStartDate(){
  65. var monthStartDate = new Date(nowYear, nowMonth, 1);
  66. return formatDate(monthStartDate);
  67. }
  68. //获得本月的停止日期
  69. function getMonthEndDate(){
  70. var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
  71. return formatDate(monthEndDate);
  72. }
  73. //获得上月开端时候
  74. function getLastMonthStartDate(){
  75. var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
  76. return formatDate(lastMonthStartDate);
  77. }
  78. //获得上月停止时候
  79. function getLastMonthEndDate(){
  80. var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
  81. return formatDate(lastMonthEndDate);
  82. }
  83. //获得本季度的开端日期
  84. function getQuarterStartDate(){
  85. var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
  86. return formatDate(quarterStartDate);
  87. }
  88. //或的本季度的停止日期
  89. function getQuarterEndDate(){
  90. var quarterEndMonth = getQuarterStartMonth() + 2;
  91. var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
  92. return formatDate(quarterStartDate);
  93. }

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(blob:http://i.cnblogs.com/1bdeb747-0e19-44de-a228-2fcf6c15e695);@import url(/css/cuteeditor.css);