简体   繁体   English

UNIX时间戳总是在GMT?

[英]UNIX timestamp always in GMT?

UNIX timestamp always in GMT? UNIX时间戳总是在GMT?

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 谢谢

是的,UNIX时间戳表示从GMT+0 unix-time纪元开始经过的秒数

UNIX timestamp (AKA Unix's epoch) means elapsed seconds since January 1st 1970 00:00:00 UTC (Universal Time). UNIX时间戳(AKA Unix的纪元)表示自1970年1月1日00:00:00 UTC(世界时)以来经过的秒数。 So , if you need the time in a specific TimeZone, you should convert it. 因此,如果您需要特定TimeZone中的时间,则应进行转换。

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. 即使技术上可行,我也会建议其他方法来获取当前时间(或任何其他时间),例如在返回之前已考虑本地时区的getdate

Yes, time is supposed to return UTC. 是的, time应该返回UTC。 If you want that converted to local time, you need a function like, ..., hmm, let me think, .., yes, that's it, localtime :-) 如果您希望转换为本地时间,你需要这样的函数,......,嗯,让我想想,......,是的,就是这样, 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. 请按照上面的链接获取每个上面的PHP文档。 Not sure if PHP has the gmtime equivalent. 不确定PHP是否具有gmtime等效项。


And, as an aside, be very careful searching the web for the time manpage with man time - you may not get what you expect. 而且,顺便说一句,必须非常小心,在网上搜索了time与联机帮助man time -你可能不会得到你所期望的。 You certainly won't get what you expect if you're looking for the manpage for man itself: man man . 如果你正在寻找man自己的联机帮助页,你当然不会得到你所期望的: man man

That is, unless you're looking for different things than I was :-) 也就是说,除非你在寻找与我不同的东西:-)

Technically, no. 从技术上讲,没有。

Even though epoch time is the means elapsed seconds since 1/1/70 00:00:00 the real "GMT" (UTC) is not. 即使纪元时间是自1/1/70 00:00:00以来经过的1/1/70 00:00:00真正的“GMT”(UTC)也不是。

UTC time 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中阅读更多内容。

Check the return value of date_default_timezone_get() to see what the default time zone is. 检查date_default_timezone_get()的返回值以查看默认时区。 The link also lists the ways you can change the value, the preferred being by setting date.timezone in php.ini. 该链接还列出了您可以更改值的方法,首选是在php.ini中设置date.timezone。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM