I want the user to enter an appointment date and time and send him a reminder an hour before it.
On the server I want to store the date-time in UTC, but on the client the user will enter it in his local time. Whats the best way to deal with this conversion?
Is there a plugin that natively supports this?
Yes, there’s a plugin which detects the timezone according to the system-information (jsTimezoneDetect). Actually a
date-object itself stores the information (but it’s kinda wierdo!).There’s an interesting article and an interesting answer here on SO, which is worth a read!
As you will read this article, you’ll get a deeper understanding of the problem “date/dst/utc/timezones in javascript” – therefore it would be interesting if you tell us more about your server-side:
The “correct” approach (which is fail-safe if you have the backend behind it) will be: let the user work with a datetime – in the browser-scope it’s more or less “undefined” (no need to find the timezone, offset, or anything alike!). Now you provide this “undefined” datetime information to the server (eg sending the unix-timestamp with a hiddenfield to the server), where you have the information which actual timezone the user is assigned to. So you can now translate this “undefined” datetime-information to a time-zone aware datetime-object on the server-side and assign the information of your account-scope to it (now the “undefined” datetime-object has a local time-zone – eg “Pacific Daylight Time”). Now you can easily do any conversion you want.
The only downside of this approach is, that you will have 2 scopes of defining a timezone (OS of the user and your webapp) – but anything else is fiddling and not fail-safe!