【发布时间】:2016-04-19 05:46:10
【问题描述】:
我只想计算时间戳的午夜值。例如 1461043742 这是今天的时间戳,从中我想要午夜 12 点时钟时间戳值的时间戳。这是 1461130928 明天的时间戳,我想显示明天午夜 12 点的时间戳值。我该怎么做,有没有可能在 PHP 中实现这一点?
【问题讨论】:
标签: php unix-timestamp
我只想计算时间戳的午夜值。例如 1461043742 这是今天的时间戳,从中我想要午夜 12 点时钟时间戳值的时间戳。这是 1461130928 明天的时间戳,我想显示明天午夜 12 点的时间戳值。我该怎么做,有没有可能在 PHP 中实现这一点?
【问题讨论】:
标签: php unix-timestamp
你可以使用strtotime:
// Input:
$now = 1461043742;
// Calculate:
$midnight = strtotime("midnight", $now);
$midnight_tomorrow = strtotime("midnight tomorrow", $now);
// Test
print(date('c', $midnight));
print(date('c', $midnight_tomorrow));
【讨论】:
您需要将小时和分钟更改为午夜。
$date = new DateTime() // By default gets the current time
$date.setTime(0,0,0) // Midnight hour
$stamp = date.getTimestamp()
【讨论】:
你可以使用 strtotime
$date = '2016-04-18 00:00:00';
$timestamp = strtotime($date);
$date = date('Y-m-d 00:00:00');
$timestamp = strtotime($date);
【讨论】: