PHP:如何获得“给定月份的一周中第n次事件”

时间:2022-10-21 10:05:52

How to get the what is the Occurrence Of A today Of The Week for a this month ??

这个月的一个星期的今天发生了什么事?

Ex: this month starts from friday and so its(first Friday) and in this case first Sunday comes in 2nd week

这个月从星期五开始,所以是(第一个星期五),在这种情况下,第一个星期天是第二周

I want to get what is the occurrence of today of this week for this month like today is

我想知道像今天这样这个月这个星期发生了什么事

EX : "1st thursday of 2nd week "

例句:“第二周第一个星期四”

1 个解决方案

#1


0  

Here's the php code I use. It may not be the best way, but at least it's an answer.

下面是我使用的php代码。这可能不是最好的方法,但至少是一个答案。

    $wkDay = date('w', mktime(0, 0, 0, $date->month, 1, $date->year));
    $weekCount = 1;
    $monthDay = $date->day;
    while ($monthDay > 7) {
        --$monthDay;
        ++$weekCount;
    }

My date class is structured to store day, month, and year values as numerical integers. The first line grabs the day of the week on the first day of the month I'm checking for. The week counter is initialized to one because I'm using it directly for output (e.g. echo "The ".$weekCount."th Tuesday of the month.";) Then I just take the day and increment my weeks each time I subtract seven.

我的date类的结构是将day、month和year值存储为数字整数。第一行是在我检查的月份的第一天。周计数器初始化为1,因为我将它直接用于输出(例如echo“The”.$weekCount)。“这个月的第一个星期二。”然后我只需要用一天的时间来增加我的周数,每次减去7。

#1


0  

Here's the php code I use. It may not be the best way, but at least it's an answer.

下面是我使用的php代码。这可能不是最好的方法,但至少是一个答案。

    $wkDay = date('w', mktime(0, 0, 0, $date->month, 1, $date->year));
    $weekCount = 1;
    $monthDay = $date->day;
    while ($monthDay > 7) {
        --$monthDay;
        ++$weekCount;
    }

My date class is structured to store day, month, and year values as numerical integers. The first line grabs the day of the week on the first day of the month I'm checking for. The week counter is initialized to one because I'm using it directly for output (e.g. echo "The ".$weekCount."th Tuesday of the month.";) Then I just take the day and increment my weeks each time I subtract seven.

我的date类的结构是将day、month和year值存储为数字整数。第一行是在我检查的月份的第一天。周计数器初始化为1,因为我将它直接用于输出(例如echo“The”.$weekCount)。“这个月的第一个星期二。”然后我只需要用一天的时间来增加我的周数,每次减去7。