简体   繁体   English

日期时间时区mysql和php计算

[英]date time timezone mysql and php calculation

i have a question about processing valid date and time with time zone in applications using php and mysql. 我对使用php和mysql在应用程序中处理带有时区的有效日期和时间有疑问。

mysql datetime object dosnt save timezone information. mysql datetime对象dosnt保存时区信息。 so i cant save many timezones in database. 所以我不能在数据库中保存许多时区。 but in php applications each user can be has own time zone using php script date_default_timezone_set() ... so problem will be appear when. 但是在php应用程序中,每个用户都可以使用php脚本date_default_timezone_set()来拥有自己的时区...因此,何时出现问题。

user     timezone            lastchange
user1    UTC                 2012-01-01 12:20:00
user2    Australia/Melbourne 2012-01-01 12:19:00

but in calculation user2 lastchange is lower than user1 lastchange but in real world is negative. 但在计算中user2 lastchange低于user1 lastchange,但在现实世界中为负。

what's the best solution for solve this issue? 解决此问题的最佳解决方案是什么?

I think you have to stock the time to your timezone, and when you want to display it, use the function : date(), and pass it a timestamp corrected to the timezone of the user ! 我认为您必须将时间存储到您的时区,并且当您要显示它时,请使用函数:date(),并将经过校正的时间戳传递给用户的时区! mktime will help you with the timestamp, because you can pass to it negative integer to back in time ;) mktime将为您提供时间戳记,因为您可以将负数传递给它,以便及时返回;)

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

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