我只想计算时间戳的午夜值。例如1461043742这是今天的时间戳,我想要午夜12点的时间戳值。这是1461130928个明天的时间戳,我想展示明天午夜12点的时间戳值。我该怎么做呢,有没有可能用PHP来实现呢?
发布于 2016-04-19 14:01:12
您可以使用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));发布于 2016-04-19 14:00:45
您需要将小时和分钟更改为午夜小时。
$date = new DateTime() // By default gets the current time
$date.setTime(0,0,0) // Midnight hour
$stamp = date.getTimestamp()发布于 2016-04-19 13:54:34
您可以使用strtotime
$date = '2016-04-18 00:00:00';
$timestamp = strtotime($date);
$date = date('Y-m-d 00:00:00');
$timestamp = strtotime($date);https://stackoverflow.com/questions/36709574
复制相似问题