PHP添加时间 [英] PHP add time to date
本文介绍了PHP添加时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个php时间 09:00,我想将其设置为日期时间。
I have a php time "09:00" that I want to set as the time for a date.
$date="2016-08-21 00:00:00.000000";
$time="09:00";
所以理想地:
$datetime=$date+$time;//<----------what is the function for this
echo $datetime;
给出 2016-08-21 09:00:00.000000
gives "2016-08-21 09:00:00.000000"
或
$date="2016-08-21 00:00:00.000000";
$time="17:30";
然后
$datetime=$date+$time;//<----------what is the function for this
echo $datetime;
给出 2016-08-21 17:30:00.000000。
一个看似简单的要求,我找不到解决方案。
gives "2016-08-21 17:30:00.000000". A seemingly simple requirement I cannot find a solution to.
推荐答案
正在添加答案的马克这就是我所拥有的但是似乎很笨拙-我希望有更好的方法:
Pending Mark adding an answer this was what I had but it seems clumsy - I hoped there was a better way:
$timebits = explode(":", $timepart);
$now->setTime($timebits[0], $timebits[1], $timebits[2]);
这篇关于PHP添加时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文