繁体   English   中英

下一次出现的Unix时间戳为4 pm、5:20pm等

[英]Unix timestamp of the next occurrence of 4pm, 5:20pm, etc

PHP中的任何想法如何获取下一个发生的指定小时和分钟的Unix时间戳?

谢谢

调用strtotime("4pm")将为您提供今天下午4点的时间。 如果已经超过下午4点,则可以将60*60*24添加到给定的时间戳记中

// Example blatantly copied from AndrewR, but it uses strtotime   
$nextfourpm = strtotime("4pm");    
if ($nextfourpm < time()) {
  $nextfourpm += 60*60*24;
}

你可以做这样的事情。

$nextTime = mktime(16, 0, 0);
if($nextTime < time()){
    $nextTime += 86400;
}

现在是15:20

你想明天16:22

最好的方法是通过发布您想超越的小时+和分钟+创建功能-纯粹的时间差异)。 通过这种方式,PHP不会犯任何错误。 PHP在处理日期和内容时会出错。

//stuff to post..
$hour = 25;
$minute = 2;

           function makemydate($hour,$minute)
           {
              if($hour > 0) 
              { 
              $hour = ($hour*3600); 
              }

              if($minute > 0) 
              { 
              $minute = ($minute*60);
              }

            $add = ($hour+$minute);
            $now = time();

            $unixtimestamp = ($now+$add);
            return $unixtimestamp;
           }

    echo makemydate;

在那里,它带有一个unix时间戳。您需要指定时间:P

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM