UNIX 时间戳始终为 GMT?

发布于 2024-09-01 17:52:01 字数 113 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

〗斷ホ乔殘χμё〖 2024-09-08 17:52:01

是的,UNIX 时间戳表示从 GMT+0 中的 UNIX 时间纪元过去了多少秒

yep, UNIX timestamp represents how much seconds past from unix-time epoch in GMT+0

爱格式化 2024-09-08 17:52:01

从技术上来说,不。

尽管纪元时间是自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.

尘世孤行 2024-09-08 17:52:01

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.

燕归巢 2024-09-08 17:52:01

是的,time 应该返回 UTC。如果你想将其转换为当地时间,你需要一个类似的函数,...,嗯,让我想想,..,是的,就是这样,localtime :-)

这将为您提供一个更有用的表单,其中各个字段被分解。

请点击上面的链接获取每个版本的 PHP 文档。不确定 PHP 是否有等效的 gmtime


顺便说一句,在网上搜索带有 man timetime 联机帮助页时要非常小心 - 您可能不会得到您所期望的结果。如果您正在寻找 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 with man time - you may not get what you expect. You certainly won't get what you expect if you're looking for the manpage for man itself: man man.

That is, unless you're looking for different things than I was :-)

沫尐诺 2024-09-08 17:52:01

检查 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文