简体   繁体   中英

converting any date having timezone to UTC

I am working on converting any date having timezone to UTC.

i have offset i wants to convert UTC time from that particular time by adding/subs rating offset like +5300 can any one help me how write PHP code for the same.

I have tried following code :

$d = new DateTime('2010-01-31 20:30:00');
$d->modify('+5300 hours');
echo $d->format('Y-m-d H:i:s'), "\n";`

If the time stamp is 2010-01-31 20:30:00+5300, then you would want to do:

$d = new DateTime('2010-01-31 20:30:00');
$d->modify('-53 hours');

5300 stands for 53 hours, 0 minutes, not 5300 hours. Also you need to subtract that to get back to UTC, it is already ahead of UTC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM