How do I handle time zones/offsets when displaying "posts" from various users?
It seems relativley easy. Take javascript time (i.e. client side), compare it to your php time (server side), and you have the offset. Save all the times in server time into your mysql table and then when displaying them, add/subtract the offset depending up on the user. I'm guessing this is under 10 lines of code. I don't determine the timezone as only the offset is neede开发者_JAVA技巧d.
The reason I ask is b.c. this site seems to make it seem a lot more involved. Is there something I'm missing?
Slapdash Answer: Nah, what makes his example more complicated is he is trying to find the timezone, you don't (from the sound of it) care about that, you just need to adjust the client time to the server's time.
And the way you suggested it is how I do it for a similar problem, and it works just fine.
Deeper Answer: You could save the client's timezone, and come up with the delta on the fly, but, unless you have several servers across different timezones, or are moving servers around in timezones, or are concerned about daylight savings (which is not observed internationally), then, your solution should be fine.
The simple offset works in just that, simple cases. The more thorough of taking the timezone and only saving the server time and then producing the offset later will scale better.
Update A smart person pointed out that the client time is not always accurate, and indeed it is not. An ideal solution would be to just ask the user what timezone they are in.
精彩评论