本文介绍了在 PHP 中将时区设置为 UTC (0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
为什么会这样?
date_default_timezone_set('Australia/Currie');
但这似乎根本没有任何效果?
But this doesn't seem to take any effect at all?
date_default_timezone_set('UTC');
将时区设置为 UTC 时,此值不会改变:
This value doesn't change when setting the timezone to UTC:
echo date('Y-m-d H:i:s', time());
我使用的是php 5.2.13,我的服务器时区是:
I'm using php 5.2.13, and the timezone of my server is:
$server_tz = date_default_timezone_get();
echo $server_tz; //outputs 'America/Guayaquil'
这是原始代码:
echo time() . "<br>
";
date_default_timezone_set('UTC');
echo time() . "<br>
";
输出:
1317235130
1317235130
推荐答案
问题是您正在显示 time(),它是基于 GMT/UTC 的 UNIX 时间戳.这就是它不改变的原因.另一方面,date()格式化基于该时间戳的时间.
The problem is that you're displaying time(), which is a UNIX timestamp based on GMT/UTC. That’s why it doesn’t change. date() on the other hand, formats the time based on that timestamp.
timestamp 是自 Unix 纪元(格林威治标准时间 1970 年 1 月 1 日 00:00:00)以来的秒数.
A timestamp is the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
echo date('Y-m-d H:i:s T', time()) . "<br>
";
date_default_timezone_set('UTC');
echo date('Y-m-d H:i:s T', time()) . "<br>
";
这篇关于在 PHP 中将时区设置为 UTC (0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)