<html>
<head>
<script type="text/javascript">
function getWeekStartDate() {
var now = new Date();
var start = new Date();
var n = now.getDay();
if (n == 0) {n = 7; }
start.setDate(now.getDate() - n + 1);
return new Date(start.getFullYear(), start.getMonth(), start.getDate());
}
function getWeekEndDate() {
var now = new Date();
var end = new Date();
var n = now.getDay();
if (n == 0) { n = 7; }
end.setDate(now.getDate() - n + 7);
return new Date(end.getFullYear(), end.getMonth(), end.getDate());
}
function getMonthStartDate() {
var now = new Date();
return new Date(now.getFullYear(),now.getMonth(),1);
}
function getMonthEndDate() {
var now = new Date();
var m_year = now.getFullYear();
var m_month = now.getMonth();
var lastMonth = new Date(m_year,m_month + 1, 1);
var currentMonth = getMonthStartDate();
var n = (lastMonth - currentMonth)/(1000*60*60*24);
var end = new Date(m_year, m_month, n);
return end;
}
function Time_DayType() {
var now = new Date();
Time_Display(now, now);
}
function Time_YesterdayType() {
var now = new Date();
now.setDate(now.getDate() - 1);
Time_Display(now, now);
}
function Time_WeekType() {
Time_Display(getWeekStartDate(), getWeekEndDate());
}
function Time_MonthType() {
Time_Display(getMonthStartDate(),getMonthEndDate());
}
function Time_Display(m_start, m_end) {
start = m_start.getFullYear() + "-" + (m_start.getMonth() + 1) + "-" + m_start.getDate();
end = m_end.getFullYear() + "-" + (m_end.getMonth() + 1) + "-" + m_end.getDate();
//
alert("时间开始于:" + start + ",结束于" + end);
}
</script>
</head>
<body>
<input type="button" οnclick="Time_DayType();" value="今日按钮" name="今日按钮">
<input type="button" οnclick="Time_YesterdayType();" value="昨日按钮" name="昨日按钮">
<input type="button" οnclick="Time_WeekType();" value="本周按钮" name="本周按钮">
<input type="button" οnclick="Time_MonthType();" value="本月按钮" name="本月按钮">
</body>
</html>
JS 本周-本月
最新推荐文章于 2024-08-02 16:50:48 发布