js获得本周,本月,本季度的开始日期和结束日期

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

js获得本周,本月,本季度的开始日期和结束日期的相关文章

JS获取本周、本季度、本月、上月的开始日期、结束日期

/** * 获取本周.本季度.本月.上月的开始日期.结束日期 */var now = new Date(); //当前日期 var nowDayOfWeek = now.getDay(); //今天本周的第几天 var nowDay = now.getDate(); //当前日 var nowMonth = now.getMonth(); //当前月 var nowYear = now.getYear(); //当前年 nowYear += (nowYear < 2000) ? 1900 : 0

* 获取本周、本季度、本月、上月的开始日期、结束日期

/** * 获取本周.本季度.本月.上月的开始日期.结束日期 */ var now = new Date();                    //当前日期 var nowDayOfWeek = now.getDay();         //今天本周的第几天 var nowDay = now.getDate();              //当前日 var nowMonth = now.getMonth();           //当前月 var nowYear = now.getY

js获取某周、某月、下月、某季度的开始日期、结束日期及判断日期第几周

/** * 获取某周.某月.上月.某季度的开始日期.结束日期及判断日期第几周 */ //格式化日期:yyyy-MM-dd function formatDate(date) { var myyear = date.getFullYear(); var mymonth = date.getMonth()+1; var myweekday = date.getDate(); if(mymonth < 10){ mymonth = "0" + mymonth; } if(myweekd

php日期处理 -- 获取本周和上周的开始日期和结束日期(备忘)

Learn From: http://www.phpernote.com/php-function/1019.html 直接贴代码: 1 <?php 2 header('Content-type: text/html; charset=utf-8'); 3 4 $date=date('Y-m-d'); //当前日期 5 6 $first=1; //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期 7 8 $w=date('w',strtotime($date)); //获取当

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

Js代码 /** * 获取本周.本季度.本月.上月的开端日期.停止日期 */ var now = new Date(); //当前日期 var nowDayOfWeek = now.getDay(); //今天本周的第几天 var nowDay = now.getDate(); //当前日 var nowMonth = now.getMonth(); //当前月 var nowYear = now.getYear(); //当前年 nowYear += (nowYear < 2000) ? 19

确定指定年份季度的开始日期和结束日期

SQL代码如下: SELECT sn AS 季度, (sn - 1) * 3 + 1 AS 开始月份, ADD_MONTHS(TRUNC(TO_DATE(年, 'yyyy'), 'yy'), (sn - 1) * 3) AS 开始日期, ADD_MONTHS(TRUNC(TO_DATE(年, 'yyyy'), 'yy'), sn * 3) - 1 AS 结束日期 FROM (SELECT '2015' AS 年, LEVEL AS sn FROM DUAL CONNECT BY LEVEL <=

php获取本周和上周的开始日期和结束日期

<?php header('Content-type: text/html; charset=utf-8'); $date=date('Y-m-d'); //当前日期 $first=1; //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期 $w=date('w',strtotime($date)); //获取当前周的第几天 周日是 0 周一到周六是 1 - 6 $now_start=date('Y-m-d',strtotime("$date -".($w ?

PHP 时间获取本周 本月 本季度用法

<?php        $week_begin = mktime(0, 0, 0,date("m"),date("d")-date("w")+1,date("Y"));$week_end = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")); echo $week_begi

js获取时间(本周、本季度、本月..)

/** * 获取本周.本季度.本月.上月的开端日期.停止日期 */ var now = new Date(); //当前日期 var nowDayOfWeek = now.getDay(); //今天本周的第几天 var nowDay = now.getDate(); //当前日 var nowMonth = now.getMonth(); //当前月 var nowYear = now.getYear(); //当前年 nowYear += (nowYear < 2000) ? 1900 :