日期:2014-05-18  浏览次数:20355 次

js得到本周和下周的日期(在線等)
js得到本周和下周的日期..周期是從星期六到星期五.比如今天是4號 那么本周的日期是 2號-8號
  我想用js得到本周和下周的日期 在線等 最好貼代碼 謝謝!

------解决方案--------------------
JScript code

 //获取日期差
        function getDate(date, dayspan)
        {
            var time = date.valueOf();
            time += (dayspan * 24 * 60 * 60 * 1000);
            return new Date(time);
        }
        
        // w为0为当前周,1为下周
        function getWeek(w)
        {
            var date = new Date();
            var x = date.getDay();
            var msg = "";
            
            var weekFirst = getDate(date, w * 7 - x);
            var weekLast = getDate(date, 6 - x + w * 7);
            msg = weekFirst.getFullYear() + "-" + eval(weekFirst.getMonth() + 1) + "-" + weekFirst.getDate();
            msg += "___" + weekLast.getFullYear() + "-" + eval(weekLast.getMonth() + 1) + "-" + weekLast.getDate();
            
            return msg;
        }
        alert(getWeek(0));
        alert(getWeek(1));