如果我有一个随机的unix时间戳,我怎样才能将其四舍五入到今天的午夜或用户选择的午夜。原因是我希望在某一天的午夜之后添加小时和分钟。
例如,如果时间戳是1324189035
,那么我该如何删除将时间戳放在当天午夜的小时,分钟和秒。
echo date('d-m-Y H:i:s', strtotime('today', 1324189035));
由于你如何使用它,我根本不计算午夜:简单地将你添加到时间戳的内容转换为24小时时间然后使用strtotime要容易得多:
echo strtotime("0:00",1324189035); // 1324184400
echo strtotime("17:50",1324189035); // 1324248600
如果你想让人类可读,请使用date
和m/d/Y H:i:s
:
echo date('m/d/Y H:i:s', strtotime('17:50',1324189035)); // 12/18/2011 17:50:00
简单地使用
strtotime('today midnight');
做就是了
date('d-m-Y',strtotime('today'));
简单!