unix timestamp round to midnight

两盒软妹~` 提交于 2019-11-27 15:41:19

问题


If I have a random unix timestamp, how can I round it down to today's midnight or the midnight selected by the user. The reason for this is that I want to add hours and minutes after a certain day's midnight.

For example if the timestamp is 1324189035 then how can I remove the hours, minutes, and seconds to put the timestamp at midnight for that day.


回答1:


echo date('d-m-Y H:i:s', strtotime('today', 1324189035));



回答2:


Because of how you're using it, I wouldn't calculate midnight at all: it is far easier to simply convert what you're adding to the timestamp into 24 hour time and then use strtotime:

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

And if you want to have that in human readable, use date and m/d/Y H:i:s:

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



回答3:


Simply Use

strtotime('today midnight');



回答4:


Just do

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

Easy!



来源:https://stackoverflow.com/questions/8550236/unix-timestamp-round-to-midnight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!