博客园站长
这是人类成长进步中记录的每一时刻
<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" onclick="getQuarterStartMonth()" />
</div>
</body>
</html>

  

posted on 2012-06-21 14:29  dm3344  阅读(709)  评论(0编辑  收藏  举报