JQuery Date Picker - TimeZone Issue

We use jQuery date picker on our website to select dates and times for booking. The calendar is currently set to PST, and this causes errors when users try to access from other time zones. If we configure the server as UTC and the application automatically selects the user's time zone based on their IP address. I was curious if we will also enable manual selection, since automatic selection may fail (i.e. when the user is working through a proxy). Any advice would be greatly appreciated.

+6
jquery date timezone jquery-ui-datepicker
source share
3 answers

The user already selects his time zone, which is located in the OS settings. Use javascript to detect this timezone (non-IP based) and pass it along with the date picker value to the server application. You can convert local time to UTC time in Javascript or server side, depending on what you prefer. But keep the server-side application in UTC, as it is good practice and internally that some languages ​​use, for example, java.util.Date in Java.

+7
source share

I would venture to guess that the front end does not need ANY understanding of time zones in general.

When they pick the time from the datepicker, just pass it back as it is (if they chose 9PM, just return 9PM). On the server, convert this date and time to a timestamp.

At this point, you can make adjustments for the IP-based custom time zone or, nevertheless, you decide to implement this. You can simply add or subtract the clock from your target time according to the user's time zone.

However, this means that you will also need to re-parse the time when you output them to make sure that they display as they should. For example, if you store a Unix timestamp, make sure that you print the formatted date based on the user's location.

You should definitely allow the user to choose their own timezone to override, but you do this by default.

+2
source share

If you need to display the time in the web interface:

  • calculate client time in seconds (Unix time) using Date.getTime () / 1000; respectively Date.setTime (utc_seconds * 1000); note that javascript uses milliseconds
  • transfer all time between client and server as seconds (Unix time)
  • store time as UTC timestamps (the probability that your backend supports conversion to UTC timestamps)

If you need to do other things on a server with a humanoid time (for example, send an email that includes meeting time):

  • grab the timezone in the client (e.g. using jsTimezoneDetect ) and save it to the server
  • use captured timezone for server computing for user

Warnings:

  • no matter what mechanism, IP-based positioning is imperfect; I would not use it to detect the time zone
  • most non-Windows systems use the tz database ; if your end is Microsoft, you may need to convert to standard Windows time zones
  • while time zone detection swells, things may go wrong, as some jurisdictions change time zones ad hoc;
  • for your application, I predict a lot of pain when changing time zone rules if you support recurring meetings; OS usually includes this in service packs
  • you can consider a mechanism that allows the user to manually set the time zone (possibly after automatic detection).
+1
source share

All Articles