Converting between timezones in PHP(在 PHP 中的时区之间转换)
问题描述
我正在转换这个时间和日期:
I am converting this time and date:
Thu, 31 Mar 2011 02:05:59 GMT
转为以下时间日期格式:
To the following time and date format:
Monday March 28 2011 4:48:02 PM
我正在使用以下 PHP 代码来完成此操作,但我想将所有时区转换为 PST/PDT.我查看了 PHP 手册并看到了这个 date_default_timezone_set()
但我不确定如何在下面的代码中实现它.
I am using the following PHP code to accomplish this, but I want to convert all time zones to PST/PDT. I looked at the PHP manual and saw this date_default_timezone_set()
but I am not sure how to implement that into the code I have below.
$date = $messages[0]->CreationTime;
echo date('l F j Y g:i:s A I', strtotime($date))
推荐答案
我不会将 date_default_timezone_set
用于一般的 TZ 转换.(澄清一下......如果这是出于显示目的,脚本范围,那么使用默认时区是合理的做法.)
I would not use date_default_timezone_set
for general TZ conversions. (To clarify... if this is for display purposes, script wide, then using the default timezone is a reasonable thing to do.)
相反,我会使用类似的东西:
Instead, I would use something like:
$tz = new DateTimeZone('America/Los_Angeles');
$date = new DateTime('Thu, 31 Mar 2011 02:05:59 GMT');
$date->setTimezone($tz);
echo $date->format('l F j Y g:i:s A I')."
";
这篇关于在 PHP 中的时区之间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PHP 中的时区之间转换


基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01