在PHP中将时区偏移量转换为友好名称 [英] Converting timezone offset to friendly name in PHP

查看:77
本文介绍了在PHP中将时区偏移量转换为友好名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP将RFC时间戳转换为友好日期。例如:

I'm trying to convert a RFC timestamp to a friendly date using PHP. Here's the example:

Wed, 17 Feb 2010 19:44:01 -0500

我要打印为:

Wed, 17 Feb 2010 19:44:01 EST

使用date()+ strtotime()

Using date() + strtotime() doesn't seem to do the trick because it converts it to the server's timezone (in my case PST).

有没有简单的方法可以对所有GMT偏移量执行此操作,因为它似乎将其转换为服务器的时区(在我的情况下为PST)。 ?似乎必须存在。

Is there a simple way to do this for all GMT offsets? Seems like there must be.

推荐答案

请参见 strototime() date()

echo date('D, j M Y G:i:s T', strtotime('Wed, 17 Feb 2010 19:44:01 -0500));
//Wed, 17 Feb 2010 19:44:01 EST

更新:要设置时区,请参见 date_timezone_set() 。如果您需要根据字符串中的偏移量设置时区,则可能需要进行一些解析。如需帮助,请参见 date_parse_from_format() 和相关函数getdate(),date_parse()等。 http://us2.php。净/手册/zh/ref.datetime.php

Update: To set the timezone see date_timezone_set(). If you need to set the timezone according to the offset in the string you may have to do some parsing. For some help, see date_parse_from_format() and related functions getdate(), date_parse(), etc. http://us2.php.net/manual/en/ref.datetime.php

这篇关于在PHP中将时区偏移量转换为友好名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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