季度的计算方法

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">
        //获得本季度的开始月份     
        function getQuarterStartMonth() {
            var quarterStartMonth = "";
            var now = new Date();
            var nowMonth = now.getMonth();
            var nowYear = now.getFullYear();    //当前年  


            if (nowMonth < 3) {
                quarterStartMonth = nowYear + '-' + '01-01';
            }
            if (2 < nowMonth && nowMonth < 6) {
                quarterStartMonth = nowYear + '-' + '04-01';
            }
            if (5 < nowMonth && nowMonth < 9) {
                quarterStartMonth = nowYear + '-' + '07-01';
            }
            if (nowMonth > 8) {
                quarterStartMonth = nowYear + '-' + '10-01';
            }
            alert("这是季起始日期"+getQuarterEndMonth(quarterStartMonth));// 起始日期
            alert("这是季结束日期"+quarterStartMonth); //结束日期
         
        }




        function getQuarterEndMonth(str_dt) {
            //var str_dt = '2011-12-16';
            var day = str_dt.substring(str_dt.lastIndexOf('-') + 1);  //获取源数据的天数值,这里是31


            var dt = new Date(str_dt);
            var result = [];


            dt.setMonth(dt.getMonth() - 15);  //这边是减5季  ,因为每季3个月。所以是15个月


            result.push(dt.getFullYear());


            //计算结果日期值<源数据日期值时,说明日期值超过当月最大天数,日期值修改为当月最大天数值
            if (dt.getDate() < day) {
                result.push(dt.getMonth());
                dt.setDate(0);
            }
            else result.push(dt.getMonth() + 1);
            result.push(dt.getDate());
            return result.join('-');
        }
    </script>
</head>
<body>
    <div>
        <input type="button" οnclick="getQuarterStartMonth()" />
    </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值