如何将目前的IST时间转换为UTC时间?还需要找到时间UTC时间

问题描述:

需要在IST(印度标准时间)当前时间,存储在PHP变量UTC时间转换前一小时,并使用PHP其存储到另一个变量。如何将目前的IST时间转换为UTC时间?还需要找到时间UTC时间

<?php 
    date_default_timezone_set('Asia/Kolkata'); 
    $Present=date('Y-m-d H:i'); 
    echo $Present; //to be converted to utc 


$GMT= gmdate('Y-m-d H:i', strtotime($Present)); 
?> 
+1

[PHP转换日期时间为UTC(可能的重复http://stackoverflow.com/questions/2095703/php-convert-datetime-to-utc) – NID

请仔细阅读这一点,应该解决您的问题

http://php.net/manual/en/datetime.gettimezone.php

例如:

$given = new DateTime("2014-12-12 14:18:00"); 
echo $given->format("Y-m-d H:i:s e") . "\n"; // your time 

$given->setTimezone(new DateTimeZone("UTC")); 
echo $given->format("Y-m-d H:i:s e") . "\n"; // UTC 

使用gmdate

echo gmdate('Y-m-d H:i', strtotime($Present)); 

˚F ollowing将减少1小时

echo gmdate('Y-m-d H:i', strtotime($Present.'-1 hour')); 
+0

我还需要在这个时间前一小时转换一个变量。代码更新如上。 –

+0

你能帮我吗? –

+0

是的!更新:) –

date_default_timezone_set('Asia/Kolkata'); 
$Present=date('Y-m-d H:i'); 
echo $Present; //to be converted to utc 

$date = new DateTime($Present); 
$date->setTimezone(new DateTimeZone('Africa/Abidjan')); 
echo $date->format('Y-m-d H:i'); 
+0

只有代码的答案是不鼓励的。请解释你的解决方案。 – Blackbam

尝试建在getTimezone and setTimezone PHP中,

$the_date = strtotime("2010-01-19 00:00:00"); 
echo(date_default_timezone_get() . "<br />"); 
echo(date("Y-d-mTG:i:sz",$the_date) . "<br />"); 
echo(date_default_timezone_set("UTC") . "<br />"); 
echo(date("Y-d-mTG:i:sz", $the_date) . "<br />");