1

I'm building a site that stores date/time values in UTC on the database.

When I display these values, I use javascript to convert them to the current's user timezone. This is working correctly so far.

Now I want to send some information to users by email (something like a reminder), and this should have the date time as well.

I don't want to print the UTC time in the email, and since I'm sending the email from the server I don't have access to the user's current timezone.

What's the best approach to solve this? should I store the timezone of the user whenever he logs in and use that to convert the date?

Any comments are appreciated.

willvv
  • 8,439
  • 16
  • 66
  • 101

1 Answers1

1

Yes, you can detect the user's timezone using Javascript, have the Javascript submit that information to the server, and have the server store it as a preference. If the user sometimes changes timezones you could even keep track of which one they are in most frequently and use that one.

Celada
  • 21,627
  • 4
  • 64
  • 78
  • Actually after giving it more thought I realized that even this is very error-prone since the offset I need isn't the one of the user but the one of wherever the activity is gonna take place (the date/time I'm rendering is an activity time). I'll have to use some service that gives me the time offset (from UTC) for a given location. – willvv Mar 26 '12 at 19:00
  • [There are such services](http://stackoverflow.com/questions/2406011/location-based-timezone-retrieval) but no good free ones and no good ones that can be queried offline. By the way, you want the timezone name (e.g. "America/Montreal"), not the UTC offset directly, because using the timezone by name you will automatically know when to apply a DST offset. – Celada Mar 26 '12 at 19:17
  • Actually I'd prefer one that takes lat, lng and date and it can return the offset. Again, this is not the main functionality and I think for now I'm gonna stick with the service. – willvv Mar 27 '12 at 03:05