如题
我在extjs中使用日期控件,
需求:根据控件选择一天,控件文本框内自动显示选中日期那周的周一日期与周日日期
比如我选择
2010.01.27这一天,
则应该显示
2010.01.24-2010.01.31根据选择的日期,显示选择日期那周的 周一与周日

解决方案 »

  1.   


    String.prototype.format = function() {
    var vs = arguments;
    return this.replace(/\{(\d+)\}/g, function() { return vs[parseInt(arguments[1])]; });
    };Date.prototype.format = function(formatString) {
    with (this) {
    return (formatString||"{0}-{1}-{2} {3}:{4}:{5}").format(
      getFullYear()
    , ("0" + (getMonth()+1)).slice(-2)
    , ("0" + getDate()).slice(-2)
    , ("0" + getHours()).slice(-2)
    , ("0" + getMinutes()).slice(-2)
    , ("0" + getSeconds()).slice(-2)
    );
    }
    };function getWeek(theDay) {
    var monday = new Date(theDay.getTime());
    var sunday = new Date(theDay.getTime());
    monday.setDate(monday.getDate()+1-monday.getDay());
    sunday.setDate(sunday.getDate()+7-sunday.getDay());
    return {monday:monday, sunday:sunday};
    }
    var week = getWeek(new Date());
    alert(
    week.monday.format("{0}.{1}.{2}")
    + " - " +
    week.sunday.format("{0}.{1}.{2}")
    );
      

  2.   


    objDate.getDay();  // 获得 objDate 所表示日期, 是星期几
    7-objDate.getDay(); // 计算当天距离 星期七 还有几天
    obj.setDate(obj.getDate() + n);  // 让 obj 所表示的日期往后推  n 天
    obj.setDate(obj.getDate() + 7-obj.getDay() );  // 让 obj 所表示的日期往后推到 星期七
      

  3.   

    getdate 和getday这两个函数自己去整了