在PHP中将时区设置为UTC(0)

编程入门 行业动态 更新时间:2024-10-10 08:25:24
本文介绍了在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>\n"; date_default_timezone_set('UTC'); echo time() . "<br>\n";

输出:

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.

A 时间戳是自Unix Epoch(1970年1月1日00:00:00 GMT)以来的秒数。

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>\n"; date_default_timezone_set('UTC'); echo date('Y-m-d H:i:s T', time()) . "<br>\n";

更多推荐

在PHP中将时区设置为UTC(0)

本文发布于:2023-11-23 22:20:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623017.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   中将   时区   PHP   UTC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!