【问题标题】:Number of seconds from now() to Sunday midnight [duplicate]从 now() 到周日午夜的秒数
【发布时间】:2011-06-09 04:40:44
【问题描述】:

在 PHP 中,我如何获取从 now() 到下周日午夜的秒数?

我不想要相对于特定日期的解决方案,而只是到下周日。

【问题讨论】:

    标签: php time


    【解决方案1】:
    $seconds = strtotime('next Sunday') - time();
    

    【讨论】:

      【解决方案2】:

      你可以使用

      print strtotime('next Sunday') - time();
      

      【讨论】:

        【解决方案3】:

        试试这个:

        function secs_until() {
          $now = time();
          $next = strtotime("next Sunday midnight");
          return $next - $now;
        }
        

        【讨论】:

          【解决方案4】:

          很简单:

          strtotime('next Sunday') - time()
          

          【讨论】:

            【解决方案5】:
            $seconds = mktime(0,0,0, date("n"), date("j") + (7 - date("N")), date("Y")) - time();
            

            该字符串将在几秒钟内为您提供从现在到周日早上 12:00 的差异。您可以调整 mktime() 中的前 3 个参数,为您提供一天中的可变时间(例如上午 8:45)

            【讨论】:

              猜你喜欢
              • 2012-10-03
              • 1970-01-01
              • 1970-01-01
              • 2012-08-12
              • 2012-12-31
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多