PHP:添加秒到日期 [英] PHP: add seconds to a date
本文介绍了PHP:添加秒到日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 $ adate;
其中包含:
Tue Jan 4 07:59:59 2011
我想在此日期添加以下内容:
I want to add to this date the following:
$duration=674165; // in seconds
添加秒后,我需要将结果重新格式化。
Once the seconds are added I need the result back into date format.
我不知道我在做什么,但我得到了奇怪的结果。
I don't know what I'm doing, but I am getting odd results.
注意:两个变量都是动态。现在他们等于给定的值,但下一个查询将会有不同的值。
Note: both variables are dynamic. Now they are equal to the values given, but next query they will have different values.
推荐答案
如果您使用php 5.3+你可以使用一种新的方法来实现。
If you are using php 5.3+ you can use a new way to do it.
<?php
$date = new DateTime();
echo $date->getTimestamp(). "<br>";
$date->add(new DateInterval('PT674165S')); // adds 674165 secs
echo $date->getTimestamp();
?>
这篇关于PHP:添加秒到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文