jQuery UI Datepicker and Timezones

2019-06-03 04:52发布

问题:

I use the datepicker to gererate a requested delivery date on my site. Same day delivery is available until 3pm GMT, so I run a script to move the calendars current selection on by 1 day at that time. The 3pm is generated on the server and not the client machine to ensure the correct time.

I would like to overcome this problem: Australian customers moves forward by 1 day as the date there changes naturally (they are 11 hours ahead), this means they miss out on approx 3 hours of same day delivery - but I can live with that. However, when my script kicks in at 3pm UK time they get nudged on another day.

Example: Its 3:15pm in the UK on January 26th, current date showing to UK users is now January 27th (cool), but our Auzzie users are now seeing January 28th (not cool).

Is there a way to localise the datepicker to GMT without running the clock time on the client pc.

This also affects our North American traffic - but isn't such a big issue - fixing one problem should fix the rest.

回答1:

You could geo-locate the IP address of your client and figure out the time zone accordingly and adjust the zime(day) on your site.
using Javascript: see Google API ClientLocation

edit wait. It actually would be easier to get the date directly using Javascript. What speaks against it?

  var currentDate = new Date()
  var day = currentDate.getDate()
  var month = currentDate.getMonth()
  var year = currentDate.getFullYear()
  document.write("<b>" + day + "/" + month + "/" + year + "</b>")

Apparently I'm still half asleep ;)