(Note – this isn’t a proper blog post, it is just a dot-point list of links for my own reference. Read and/or use it at your own risk.)
But how to get the user’s timezone string?
or I can get it from Google Time Zone API, but only if I already have latitude / longitude
To get the lat/long, either:
2 – Get location from the IP address using IPInfoDB (free but requires registration and only works from one server IP) or freegeoip.net (no registration required but stops after 10k queries p/h) or geoPlugin (requests registration but seems to work without it).
And once I’ve auto-detected the timezone string, I’d then need to give the user a chance to change it in a settings page, because the auto-detected value will sometimes be wrong.
…though I don’t think I need to do any of that. I’m using Facebook for my only login path, and I can get the current timezone offset from the Facebook User object. (Not the timezone string, just the offset … but that’s probably good enough, provided Fb keep it up-to-date, which they do.) No user interaction required, and it’s reliable (or at least it’s a close to reliable as Facebook is). My guess is that Fb gets it from Date().getTimezoneOffset() each time a session starts.