如何在php中找到第二天开始的unix时间戳?

时间:2010-03-26 00:22:14

标签: php unix-timestamp

我有一个当前时间的unix时间戳。我想获得第二天开始的unix时间戳。

$current_timestamp = time();
$allowable_start_date = strtotime('+1 day', $current_timestamp);

正如我现在所做的那样,我只是将整整一天添加到unix时间戳中,相反,我想知道当前一天剩下多少秒,并且只添加那么多秒才能获取第二天第一分钟的unix时间戳。

最好的方法是什么?

6 个答案:

答案 0 :(得分:26)

那段时间简单地“make”的最直接方式:

$tomorrowMidnight = mktime(0, 0, 0, date('n'), date('j') + 1);

引用:

  

我想弄清楚当天剩下多少秒,并且只添加那么多秒才能获得第二天第一分钟的unix时间戳。

不要那样做。尽可能避免相对计算,特别是如果在没有秒算术的情况下“绝对”获得时间戳是如此微不足道。

答案 1 :(得分:8)

答案 2 :(得分:3)

$tomorrow = strtotime('+1 day', strtotime(date('Y-m-d')));
$secondsLeftToday = time() - $tomorrow;

答案 3 :(得分:2)

简单的事情:

$nextday = $current_timestamp + 86400 - ($current_timestamp % 86400);

是我使用的。

答案 4 :(得分:0)

第二天的开始计算如下:

<?php

$current_timestamp = time();
$allowable_start_date = strtotime('tomorrow', $current_timestamp);

echo date('r', $allowable_start_date);

?>

如果需要遵循您的特殊要求:

<?php

$current_timestamp = time();
$seconds_to_add = strtotime('tomorrow', $current_timestamp) - $current_timestamp;

echo date('r', $current_timestamp + $seconds_to_add);

?>

答案 5 :(得分:0)

我的变体:

 $allowable_start_date = strtotime('today +1 day');
相关问题