【问题标题】:First Thursday of the month if not passed如果没有通过,每月的第一个星期四
【发布时间】:2014-04-24 16:59:17
【问题描述】:

在 PHP 中,如果即将到来,我需要显示当月的第一个星期四,如果当月的第一个星期四过去,我需要显示下个月的第一个星期四。

我以此为起点: echo date("F dS", strtotime("下个月第一个星期四"));

如何实现整个逻辑?

【问题讨论】:

    标签: php


    【解决方案1】:
    $first = strtotime('first thursday this month');
    if ($first < time()) {
       // first thursday this month already past, so...
       $first = strtotime('first thursday next month');
    }
    

    请注意,这只是一个演示逻辑的非常简单的示例。 first thursday this month 将在第一个星期四的午夜出现。如果您在上午 12:00:01 运行此代码,您仍然会检测到“星期四”已经过去。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      相关资源
      最近更新 更多