PHP 不时添加 [英] Php add time to time
本文介绍了PHP 不时添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以这种格式从数据库中获取日期
I get a date from the database in this format
hh:mm:ss
我想将其添加到当前时间并按以下格式放回另一个表中:
And I want to add this to the current time and put back to an other table with the following format:
yyyy:mm:dd hh:mm:ss
推荐答案
假设您从变量 $dbTime 中的数据库中获取时间,我会这样做:
Assuming you get the time from the database in a variable $dbTime I'd do something like this:
$timeArray = explode (":", $dbTime );
$newTime = time() + ($timeArray[0]*60*60) + ($timeArray[1]*60) + $timeArray[2];
$finalTime = date('Y-m-d H:i:s',$newTime);
可能不是最干净的方式,但它是一种选择:)
May not be the cleanest way but it is an option :)
这篇关于PHP 不时添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文