【问题标题】:Calculate UTC time from given UTC time & number of seconds in PHP从给定的 UTC 时间和 PHP 中的秒数计算 UTC 时间
【发布时间】:2014-06-11 09:52:44
【问题描述】:
a=b+c;

result_utc_time= given_utc_time + given_number_of_seconds;

这就是我想要做的。我想从 given_utc_time 和 given_number_of_seconds 计算 result_utc_time

让我的given_utc_time=2014-06-11T09:50:20Z

given_number_of_seconds=1500

有谁知道如何用 PHP 或 Javascript 做到这一点?

【问题讨论】:

  • 时间中也需要包含日期吗?
  • 看我的回答,希望是你需要的

标签: javascript php jquery html utc


【解决方案1】:

试试

$given_utc_time='2014-06-11T09:50:20Z';    
$time = strtotime($given_utc_time);
echo date('Y-m-d H:i:s', strtotime('+1500 second',$time));

或者可以使用

echo date('Y-m-d H:i:s', $time+1500);

或使用日期时间:-

$date = new DateTime($given_utc_time);
$date->add(new DateInterval('PT1500S'));
echo $date->format('Y-m-d H:i:s');

【讨论】:

  • @TheJoker 是的,它是 php var 。你想要php?
【解决方案2】:

你可以这样使用:

$a = date('h:i:s A', strtotime('2:10:20')+36000);

然后在某处回显$a

所以基本上你需要调整我刚刚放在那里的“2:10:20”来测试你想要的东西。而 36000 是它将增加它的秒数。

因此,使用 36000 时,您给的时间会增加 10 小时。所以这将输出'12:10:20 PM'。 h:i:s 后面的 A 加上 AM 或 PM,你可以不去得到 ​​p>

$a = date('h:i:s', strtotime('2:10:20')+36000); 这将回显“12:10:20

现在你也可以给它添加变量了:

$a = date('h:i:s A', strtotime($b)+$c);

然后例如:

$b = '2:10:20'; // The time
$c = 36000; //seconds to increase

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 2012-10-08
    • 2021-12-19
    • 2020-05-21
    • 2016-09-05
    • 2015-09-25
    • 2014-03-03
    相关资源
    最近更新 更多