0

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?

Mike
  • 493
  • 5
  • 14
  • In general, your question is too broad. See the duplicate question linked for much more on this subject, as well as searching and reviewing other questions with the [tag:timezone] tag. Additionally, calling time zones a "problem" is silly. They are a simply an aspect of timekeeping by humans on planet Earth. There is much documented and easily referenced on the subject, and plenty of solutions in both php and mysql that you tagged. – Matt Johnson-Pint Jul 07 '18 at 19:54
  • Thanks Matt - I think anybody else here perfectly knew what I was talking about when I mentioned timezones as a „problem“. All of them including me do not see timezones as „real world problem“. Thanks for an philosophic unnecessary answer but if it makes happy feel hugged or something...... – Mike Jul 08 '18 at 22:06

3 Answers3

1

Use it .pageloom

Use it in javascript to get timezone:

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

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)
vadim savin
  • 259
  • 2
  • 8
0

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

Ramin
  • 351
  • 2
  • 7