简体   繁体   English

php time()函数如何工作

[英]How does php time() function works

How does PHP time() work in following case: PHP time()如何在以下情况下工作:

User is posting something in database and posting stamp is added also which is just time() . 用户在数据库中发布内容并添加了发布标记,这只是时间()

But how to compensate for time zones? 但如何补偿时区? What if two users from EU and USA are posting at the same time, will the posting stamp be the same? 如果来自欧盟和美国的两个用户同时发布,发布标记是否相同怎么办?

The whole point is that the time() -method stores everything in the same timezone, the one the server is configured with. 重点是time()方法将所有内容存储在同一时区中,即服务器配置的时区。

If it did not do this, it would be impossible to know when something really happened. 如果它不这样做,就不可能知道什么时候真的发生了。

If you want to display datetime with timezones, you can output the timestamp from the server, use javascript or something to calculate the clients timezone offset and add/substract hours to the time. 如果要显示带时区的日期时间,可以从服务器输出时间戳,使用javascript或其他东西计算客户端时区偏移量,并将时间加/减小时。

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

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