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?


回答1:

Use it .pageloom

Use it in javascript to get timezone:

<script language="javascript">
function getTimezoneName() {
    timezone = jstz.determine()
    return timezone.name();
}
</script>

回答2:

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)

回答3:

In client side you can use : Moment.js to retrive timezone: https://momentjs.com/timezone/

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

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除