简体   繁体   English

仅适用于日期而非时间时的PHP / MySQL时区

[英]PHP/MySQL Timezone when working only with Date not Time

My question is more on the concept side. 我的问题更多是在概念方面。

I'm wondering how to deal with dates only based information. 我想知道如何处理仅基于日期的信息。 For example, when you have a day to take a vacation or something like that on February 24th and you store on the database as 2015-02-24 00:00:00 right.... how do I deal with conversions in this case? 例如,当您有一天要放假或2月24日之类的事情,并且您将数据库存储为2015-02-24 00:00:00时...。在这种情况下,我该如何处理转化?

I already now how to convert timezones, it works with no problem in cases where the user selects a time too. 我现在已经知道如何转换时区,在用户也选择时间的情况下,它也没有问题。 But when I use 00:00:00 in cases only the date matters I'm having problems to figure it out. 但是,当我仅在日期很重要的情况下使用00:00:00时,我就很难弄清楚。

For example: Let's say I setup my vacation to be on the 24th of February and I'm on EST right, and the system is saving all times on EST. 例如:假设我将假期设置为2月24日,并且我是在美国东部标准时间(EST),系统将所有时间保存在美国东部标准时间(EST)。 It will convert and it will be saved as 2015-02-24 00:00:00 它将转换并保存为2015-02-24 00:00:00

Then somebody on PST time will check it out, and when it convert to them it will be 2015-02-23 21:00:00 ... and it will show my vacation in their point of you it will be on the 23rd. 然后有人会在太平洋标准时间(PST)进行检查,当转换为他们时,它将是2015-02-23 21:00:00 ...并且它将向您显示我的假期,即23日。

Is that a correct logic? 这是正确的逻辑吗? How should I save on the database the time in that case? 在这种情况下,我应该如何在数据库上节省时间? Keep it as 00:00:00? 保持为00:00:00?

I hope I was able to explain myself. 我希望我能解释自己。

Thanks 谢谢

You can save the date in unix timestamp in the database (always save the current time in GMT even if you are in EST). 您可以将日期保存在数据库的Unix时间戳中(即使您处于EST,也始终将当前时间保存在GMT中)。

And when displaying the date, convert it to the user's timezone. 并且在显示日期时,将其转换为用户的时区。

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

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