unix时间戳到午夜

问题描述 投票:22回答:4

如果我有一个随机的unix时间戳,我怎样才能将其四舍五入到今天的午夜或用户选择的午夜。原因是我希望在某一天的午夜之后添加小时和分钟。

例如,如果时间戳是1324189035,那么我该如何删除将时间戳放在当天午夜的小时,分​​钟和秒。

php unix-timestamp
4个回答
19
投票
echo date('d-m-Y H:i:s', strtotime('today', 1324189035));

16
投票

由于你如何使用它,我根本不计算午夜:简单地将你添加到时间戳的内容转换为24小时时间然后使用strtotime要容易得多:

echo strtotime("0:00",1324189035); // 1324184400
echo strtotime("17:50",1324189035); // 1324248600

如果你想让人类可读,请使用datem/d/Y H:i:s

echo date('m/d/Y H:i:s', strtotime('17:50',1324189035)); // 12/18/2011 17:50:00

6
投票

简单地使用

strtotime('today midnight');

1
投票

做就是了

date('d-m-Y',strtotime('today'));

简单!

© www.soinside.com 2019 - 2024. All rights reserved.