echo date("w"); //取得星期,0为星期天
echo date("W"); //取得一年中的星期数
echo date("W",strtotime(date("Y")."-".date("m")."-01")); //取得月初的星期数
余下的你自己算

解决方案 »

  1.   

    $a=intval(date("d"));
    $b=ceil(($a-7)/7)+1;
    $c=intval(date("w"));//呵呵,0表示星期天
    echo "这个月第".$b."个星期".$c;
      

  2.   

    楼主给你这个代码吧,是唠叨原创:
    $ctime="星期".substr("日一二三四五六",date("w",$thistime)*2,2);
      

  3.   

    楼主给你这个代码吧,是唠叨原创:
    $ctime="星期".substr("日一二三四五六",date("w",$thistime)*2,2);$thistime 是什么?
      

  4.   

    哎,楼上的没有一个是正确答案(不过好像有位提供了一个简单思路)!大家都急于捞分,没有注意到我很关键的一句话“(假设每个星期是从星期1-星期7)”
    snmr_com(麒麟厍人)那个也不对,我要的是完全按照日历排布的那种,就是日历上的一行就是一个星期(每月第一个星期的天数不大于7天,而snmr_com的是等于7天)。我们按照日历的排法,也就是西方人的星期7-星期6为一个星期。差异在于,比如8.1是星期6,那么8.1就是8月的第一个星期,因为8.2是星期天,按照我们的规定,8.2就是第二个星期了。(同理我之前说的那种星期1-星期7为一个星期)最后,还是只有我自己花了点时间写了个函数出来处理。有兴趣的可以看看。
    /** 备注:该函数默认的一个星期是指从 星期天 - 星期六,和西方相同,也方便从日历上察看。
    ** 输入 参数1:年 参数2:月 参数3:日
    ** 输出 返回该日期是该年该月中的第几个星期
    */
    function weekInMonth($year,$month,$day){
    if(!checkdate($month,$day,$year)) {
    exit("Wrong date!!!");
    }
    $counter = 1;
    for($i = 1;$i <= $day; $i++){
    $strTheDay = sprintf("%s-%s-%s",$year,$month,$i);
        $theDay = getdate(strtotime($strTheDay));
    $dayOfWeek = ($theDay['wday'] == "0") ? "7" : $theDay['wday'];
    if($dayOfWeek == 7 && $i != 1) {
    $counter++;
    }
    }
    return $counter;
    }
    // for test only:
    // echo weekInMonth(2004,7,24);
      

  5.   

    把当前时间用time()存成unix时间戳,然后你想怎么计算就怎么计算了,呵呵
      

  6.   

    之前有人问过这个问题~~<%
    '///////////////////////////////////////////
    'FUNCTION:GetWeek(Date)
    'DESCRIPTION:取得该日期所在月份的当前周
    'PARA:Date要计算的日期
    'RETURN:所在周数
    'AUTHOR:愚人([email protected])
    '//////////////////////////////////////////Function GetWeek(strDate)
    Dim strMon,strYear,nWeek

    strDate = FormatDateTime(strDate,2)
    strMon = Month(strDate)
    strYear = Year(strDate)
    strDay = Day(strDate)
    nWeek = Weekday(FormatDateTime(strYear&"-"&strMon&"-1",2)) - 1

    Dim arrRange(5,2)

    for i = 0 to 4
    if i = 0 then
    arrRange(i,0) = 1
    if nWeek = 6 then
    arrRange(i,1) = arrRange(i,0) 
    else
    arrRange(i,1) = arrRange(i,0) + 6 - nWeek
    end if 
    else
    arrRange(i,0) = arrRange(i-1,1)+1
    arrRange(i,1) = arrRange(i,0) + 6
    end if
    next

    Dim currWeek

    for i = 0 to 4
    if arrRange(i,0) <= strDay and strDay <= arrRange(i,1) then
    currWeek = i + 1
    end if
    next if currWeek = "" then
    currWeek = 0 
    end if 

    GetWeek = currWeek
    End FunctionDim nWeek,cDate
    cDate = Now()
    nWeek = GetWeek(cDate)Response.write cDate & "是"&Year(cDate) &"年"&Month(cDate)&"月的第"&nWeek&"周"
    %>
      

  7.   

    然后再用Weekday得到是星期几,加起来就是第几个星期几了
      

  8.   

    参考~~~<script language="vbs">
    <!--
      Function  getweeks()
        Dim strDate,strWeek,strYear,strMonth,DDate
        Dim i,j
        strDate=document.all.Ty.value     If IsDate(strDate) Then
             strDate = Cdate(strDate)
             strYear = Cstr(Year(strDate))
             strMonth = Cstr(Month(strDate))
             Select Case Weekday(strDate)
               Case 1
                 strWeek = "星期日"
               Case 2
                 strWeek = "星期一"
               Case 3
                 strWeek = "星期二"
               Case 4
                 strWeek = "星期三"
               Case 5
                 strWeek = "星期四"
               Case 6
                 strWeek = "星期五"
               Case 7
                 strWeek = "星期六"
             End Select       For i = 1 To 31
             DDate = Cdate(strYear & "-" & strMonth & "-" & Cstr(i))
             If Weekday(DDate) = Weekday(strDate) Then
               j = j + 1
               If Cdate(DDate) = strDate Then
                 alert(Cstr(strDate) & "是" & strYear & "年" & strMonth & " 月的第" & Cstr(j) & "个" & strWeek)
                 Exit For
               End If
             End If
           Next     Else
           alert("请输入日期型数据!")
         End If
      End Function
      -->
    </script>
    Date:<input name=Ty maxlength=10>
    <input type=button name=B1 value=check onclick="getweeks ()">
      

  9.   

    怎么还没闹明白?
    “现在,我需要知道这一天是在2004年8月份的第几个星期一(假设每个星期是从星期1-星期7)”
    这里的“假设每个星期是从星期1-星期7”对“第几个星期一”简直就是风马牛不相及的,无论一个星期从星期几算起,都不会影响2004-8-23是2004年8月份的第几个星期一$d = "2004-8-23"; //待计算的日期
    $d0 = ereg_replace("[^-]+$","01",$d); //取得所在月第一天
    $t = strtotime($d); //转换为unix时间戳
    $t0 = strtotime($d0); //转换为unix时间戳echo date("W",$t)-date("W",$t0); //out 4若$d = "2004-7-20"; 则算出为3(7月的第3个星期二),你可自行验证