PHP timezones and how to display them [duplicate]

问题: This question already has an answer here: Daylight saving time and time zone best practices [closed] 30 answers How do you solve the "problem" of d...


This question already has an answer here:

How do you solve the "problem" of different timezones? Let's say I have some kind of community where people can post a status message. Problem is that users do live all over the world and the time currently is just shwon in one format...

How do I find out a users timezone, how would I save and also display it?


Use it .pageloom

Use it in javascript to get timezone:

<script language="javascript">
function getTimezoneName() {
    timezone = jstz.determine()


Working with timezone is quite tricky, and there are a lot of articles about this, check this article about all the tricks used to work timezone zone aware systems.

  • Store all the dates in a GMT format.
  • Get the user's timezone either by manual selecting the timezone from a drop-down during registration or automatically. Getting the user's timezone automatically is a bit tricky: you have to get the timezone from javascript, and make an ajax request to the server to save the timezone.
  • Display all the dates in the frontend converted into user's timezone (I have built a Trait for laravel that makes this step automatically, so I think you can do something similar in your system)


In client side you can use : Moment.js to retrive timezone:

  • 发表于 2018-07-11 17:55
  • 阅读 ( 232 )
  • 分类:sof


请先 登录 后评论


作家榜 »

  1. 小编 文章