js, 当天,当月,当年
function getCurrentDay(){
var date = new Date();
return {"start":date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(),
"end":date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()};
}
function getCurrentYear() {
var date = new Date();
return {"start":date.getFullYear() + "-01-01", "end": date.getFullYear() + "-12-31" };
}
function getCurrentMonth() {
var date = new Date();
return {"start":date.getFullYear() + "-" + (date.getMonth() + 1) + "-01",
"end": date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + getLastDay(date.getFullYear(), (date.getMonth() + 1)) };
}
$(":radio[name$=rblDateShortCut]").bind("click", function(){ setDate(); });
function setDate(){
var dateValue = $(":radio[name$=rblDateShortCut]:checked").val()
var dateRange;
if ( dateValue == "0") { // 日
$(":input[id$=txtDateStart]").val(getCurrentDay().start);
$(":input[id$=txtDateEnd]").val(getCurrentDay().end);
} else if ( dateValue == "1" ) { // 月
$(":input[id$=txtDateStart]").val(getCurrentMonth().start);
$(":input[id$=txtDateEnd]").val(getCurrentMonth().end);
} else { // 年
$(":input[id$=txtDateStart]").val(getCurrentYear().start);
$(":input[id$=txtDateEnd]").val(getCurrentYear().end);
}
}
function getLastDay(year, month) {
var new_year = year; // 取当前的年份
var new_month = month++; // 取下一个月的第一天,方便计算(最后一天不固定)
if(month>12) // 如果当前大于12月,则年份转到下一年
{
new_month -=12; // 月份减
new_year++; // 年份增
}
var new_date = new Date(new_year,new_month,1); // 取当年当月中的第一天
return (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate(); // 获取当月最后一天日期
}
分享到:
相关推荐
也是通过js实现了一款日历控件的效果,功能很不错!通过点击日历控件,可以将自己点击在日历控件上面的时间添加到Textbox中
利用js同时生成当日(YYYY-MM-DD)、当月(YYYY-MM)、当年(YYYY);通格式的上一日、上一月、上一年
它首先计算了指定日期与当年第一天之间的差值(单位:天),然后加上1(即当天的星期数减去1)后除以7并向上取整得到每周的周数。 #### 2.4 切换周功能 `downWeek`函数实现了日期的上下周切换功能。通过传入`"down...
提醒样式根据日期与当前日期的关系分为三类:当日、当年当月当日和当月当日。每种样式都有独特的视觉效果,以区分不同的提醒状态。 4. **使用方式**: - **show() 方法**:适用于已有DOM元素,如div。将该元素的...
我在文本框中录入当日产量,则在另外文本框中,当月的产量和当年的产量自动算出,请问如何实现。
通过计算当前日期与本月份最后一天的差值,再加上当天是周几,最后除以7并向上取整,得到当前日期是本月份的第几周。计算过程中,需要注意“当前周的还有几天过完(不算今天)”的逻辑,即6减去今天是周几,然后加到...
4、新加入节假日功能,现在您可以全局设定如何放假(休周末、休单周、休双周、单双轮休)以及当年法定节假日,甚至为任何一个单独用户设定个性化的休假方案了。休假期间,用户不能签到,也无法被签到记录统计程序...