UNIX 时间戳始终为 GMT?
UNIX 时间戳始终为 GMT?
我尝试运行 php 函数 time()
,当我尝试从 time() 函数转换 unix 时间戳时,输出与计算机时间不相似。
谢谢
UNIX timestamp always in GMT?
I tried to run php function time()
and when I tried to convert the unix timestamp from the time() function, the output is not similar to the computer time.
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,UNIX 时间戳表示从
GMT+0
中的 UNIX 时间纪元过去了多少秒yep, UNIX timestamp represents how much seconds past from unix-time epoch in
GMT+0
从技术上来说,不。
尽管纪元时间是自
1/1/70 00:00:00
以来经过的秒数,但真正的“GMT”(UTC)并不是。UTC 时间需要更改几次,以考虑地球自转速度的减慢。
正如大家所写,大多数人使用 UTC 纪元。
您可以在 https://en.wikipedia.org/wiki/Unix_time 中阅读更多内容。
Technically, no.
Even though epoch time is the means elapsed seconds since
1/1/70 00:00:00
the real "GMT" (UTC) is not.UTC time needed to be changed a few times to take in to account the slowing speed of the rotating earth.
As everybody wrote, most people use epoch at UTC.
You can read more in https://en.wikipedia.org/wiki/Unix_time.
UNIX 时间戳(又称为 Unix 纪元)是指自 1970 年 1 月 1 日 00:00:00 UTC(通用时间)以来经过的秒数。因此,如果您需要特定时区的时间,您应该将其转换。
尽管技术上可行,但我建议使用其他方法来获取当前时间(或任何其他时间),例如
getdate
在返回之前已经考虑了本地时区。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.
Even though is technically possible, I would recommend alternative ways to get current time (or any other time), such as
getdate
that already considers local timezone before returning.是的,
time
应该返回 UTC。如果你想将其转换为当地时间,你需要一个类似的函数,...,嗯,让我想想,..,是的,就是这样,localtime
:-)这将为您提供一个更有用的表单,其中各个字段被分解。
请点击上面的链接获取每个版本的 PHP 文档。不确定 PHP 是否有等效的
gmtime
。顺便说一句,在网上搜索带有
man time
的time
联机帮助页时要非常小心 - 您可能不会得到您所期望的结果。如果您正在寻找man
本身的联机帮助页,您肯定不会得到您所期望的结果:man man
。也就是说,除非你正在寻找与我不同的东西:-)
Yes,
time
is 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
:-)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
gmtime
equivalent.And, as an aside, be very careful searching the web for the
time
manpage withman time
- you may not get what you expect. You certainly won't get what you expect if you're looking for the manpage forman
itself:man man
.That is, unless you're looking for different things than I was :-)
检查 date_default_timezone_get() 的返回值查看默认时区是什么。该链接还列出了更改该值的方法,首选方法是在 php.ini 中设置 date.timezone。
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.