如何将UTC datetime转换为其他时区? [英] How to convert UTC datetime to another timezone?

查看:124
本文介绍了如何将UTC datetime转换为其他时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何转换这样的日期: 2012-07-16 01:00:00 +00 (它在$ code UTC +00 :00 时区)到 UTC +04:00 时区?确保夏令时将正确地被提示?

How can i convert a date like this: 2012-07-16 01:00:00 +00 (it's in the UTC +00:00 timezone) to UTC +04:00 timezone? Ensuring that daylight saving will be handelled correctly?

推荐答案

使用 DateTime DateTimeZone

$date = new DateTime('2012-07-16 01:00:00 +00');
$date->setTimezone(new DateTimeZone('Europe/Moscow')); // +04

echo $date->format('Y-m-d H:i:s'); // 2012-07-15 05:00:00 

这篇关于如何将UTC datetime转换为其他时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆