php UNIX 时间戳总是在格林威治标准时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2853977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UNIX timestamp always in GMT?
提问by bbnn
UNIX timestamp always in GMT?
UNIX 时间戳总是在格林威治标准时间?
I tried to run php function time()
我试图运行 php 函数 time()
and when I tried to convert the unix timestamp from the time() function, the output is not similar to the computer time.
当我尝试从 time() 函数转换 unix 时间戳时,输出与计算机时间不同。
Thank You
谢谢你
回答by zerkms
yep, UNIX timestamp represents how much seconds past from unix-time epoch in GMT+0
是的,UNIX 时间戳表示从 Unix 时间纪元过去的秒数 GMT+0
回答by yonatanh
Technically, no.
从技术上讲,没有。
Even though epoch time is the means elapsed seconds since 1/1/70 00:00:00the real "GMT" (UTC)is not.
尽管出现时间是手段经历的秒数,因为1/1/70 00:00:00在真正的“GMT”(UTC)不是。
UTCtime needed to be changed a few times to take in to account the slowing speed of the rotating earth.
考虑到地球自转速度变慢,UTC时间需要更改几次。
As everybody wrote, most people use epoch at UTC.
正如大家所写,大多数人在 UTC 使用纪元。
You can read more in https://en.wikipedia.org/wiki/Unix_time.
您可以在https://en.wikipedia.org/wiki/Unix_time 中阅读更多内容。
回答by Pablo Santa Cruz
UNIX timestamp (A.K.A. Unix's epoch) means elapsed seconds since January 1st 1970 00:00:00 UTC (Universal Time). So , if you need the time in a specific TimeZone, you should convert it.
UNIX 时间戳(AKA Unix 的纪元)表示自 1970 年 1 月 1 日 00:00:00 UTC(世界时)以来经过的秒数。因此,如果您需要特定时区中的时间,您应该转换它。
Even though is technically possible, I would recommend alternative ways to get current time (or any other time), such as getdatethat already considers local timezone before returning.
即使在技术上是可能的,我还是会推荐其他方法来获取当前时间(或任何其他时间),例如getdate在返回之前已经考虑了本地时区。
回答by paxdiablo
Yes, timeis supposed to return UTC. If you want that converted to local time, you need a function like, ..., hmm, let me think, .., yes, that's it, localtime:-)
是的,time应该返回UTC。如果你想把它转换成当地时间,你需要一个类似的函数,...,嗯,让我想想,..,是的,就是这样,localtime:-)
This will give you a more usable form with the individual fields broken out.
这将为您提供一个更有用的表单,其中包含单个字段。
Follow those links above for the PHP doc on each. Not sure if PHP has the gmtimeequivalent.
按照上面的链接查看每个 PHP 文档。不确定 PHP 是否具有gmtime等效项。
And, as an aside, be very careful searching the web for the timemanpage with man time- you may not get what you expect. You certainlywon't get what you expect if you're looking for the manpage for manitself: man man.
而且,顺便说一句,在网上搜索time联机帮助页时要非常小心man time- 您可能不会得到您所期望的。如果您自己寻找联机帮助页,您肯定不会得到您所期望的man:man man.
That is, unless you're looking for different things than I was :-)
也就是说,除非您正在寻找与我不同的东西:-)
回答by ScottR
Check the return value of date_default_timezone_get()to see what the default time zone is. The link also lists the ways you can change the value, the preferred being by setting date.timezone in php.ini.
检查date_default_timezone_get()的返回值以查看默认时区是什么。该链接还列出了您可以更改该值的方法,首选是通过在 php.ini 中设置 date.timezone。

