Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

php 已知一个具体的年月日时间,计算出加上一个十分秒后的时间,如何实现?

比如:

$date1 = "2016-11-25 09:53:58";

$p_time = "00:02:34";


// $date1 + $p_time

结果输出:

"2016-11-25 09:56:32"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

使用PHP内置的DateTime对象

$date = new DateTime("2016-11-25 09:53:58");
$date->add(new DateInterval('PT10S'));
// 输出为 2016-11-25 09:54:08
echo $date->format('Y-m-d H:i:s');

使用方法可以参考官方文档 http://php.net/manual/en/date...

其中增加的时间格式是遵循ISO 8601规范的。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...