先求第一周的结尾(无论是周六还是周日,最好可以设置)
用需要求的日子与 第一周比较,如果是负数的话,说明是第一周;
如果是正数可以计算共有几个七天,如果有余数的话就在加上一周。
如要求的日期是:2004-7-14,先得到2004-7-1,看它是周几(weekday),加上相应的天数就是第一周的周末。计算两个日期的时间差(可以用两个时间相减或DateDiff("d", Now, theDate)
),得到的整数,看是否是正数,如果是正数的话,要求除法和取余数;如果是负数的话,就是第一周了。
good luck!

解决方案 »

  1.   

    smonth=year(date())&"-"&month(date())&"-"&"1"
    vweeknum=datepart("ww",date())-datepart("ww",smonth)+1上面表示当前日期在第几周。把date()改成你的日期,就是你要的日期所在的周。
      

  2.   

    jycjyc(jycjyc) 请问你的datepart,是什么地方的方法,我怎么在jscript参考中没找到
      

  3.   

    Date.prototype.format = function (format){
    if (format == null) format = "yyyy/MM/dd HH:mm:ss.SSS";
    var year = this.getFullYear();
    var month = this.getMonth();
    var sMonth = ["January","February","March","April","May","June","July","August","September","October","November","December"][month];
    var date = this.getDate();
    var day = this.getDay();
    var hr = this.getHours();
    var min = this.getMinutes();
    var sec = this.getSeconds();
    var daysInYear = Math.ceil((this-new Date(year,0,0))/86400000);
    var weekInYear = Math.ceil((daysInYear+new Date(year,0,1).getDay())/7);
    var weekInMonth = Math.ceil((date+new Date(year,month,1).getDay())/7);
    return format.replace("yyyy",year).replace("yy",year.toString().substr(2)).replace("dd",(date<10?"0":"")+date).replace("HH",(hr<10?"0":"")+hr).replace("KK",(hr%12<10?"0":"")+hr%12).replace("kk",(hr>0&&hr<10?"0":"")+(((hr+23)%24)+1)).replace("hh",(hr>0&&hr<10||hr>12&&hr<22?"0":"")+(((hr+11)%12)+1)).replace("mm",(min<10?"0":"")+min).replace("ss",(sec<10?"0":"")+sec).replace("SSS",this%1000).replace("a",(hr<12?"AM":"PM")).replace("w",weekInYear).replace("W",weekInMonth).replace("E",["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day]).replace("D",daysInYear).replace(/MMMM+/,sMonth).replace("MMM",sMonth.substring(0,3)).replace("MM",(month<9?"0":"")+(month+1)).replace("F",Math.ceil(date/7));
    }
    var d = new Date();
    alert(d.format("yyyy年MM月dd日 E  kk(1~24)时mm分ss.SSS秒 今年的第D天,第w周 这个月的第W周"));
      

  4.   

    to prentice1001(徒弟)
    放在asp中
    <%
    smonth=year(date())&"-"&month(date())&"-"&"1"
    vweeknum=datepart("ww",date())-datepart("ww",smonth)+1
    response.write vweeknum
    %>