Skip to content Skip to sidebar Skip to footer

How To Avoid Time Zone Issues With JQuery Datepicker

I'm using datepicker in an input form, and sending the results through json to a database. I am using this line, to get the date from the datePicker: date = $('#datepicker').datepi

Solution 1:

I solved this a while ago, but forgot to post an answer. After retrieving date, this is how i fixed it:

date.setMinutes(date.getMinutes() - date.getTimezoneOffset());

voilla


Solution 2:

I could not figure out what you did there so I came up with a bit of a hackterrific solution.

I took the value of the alt field in UNIX:

$( function() {
    $( "#datepicker" ).datepicker({
      altField: "#alternate",
      altFormat: "@",
    });

It came out all sorts of weird with 3 extra 0's and a day behind my time zone. So I figured out the difference and added it on.

var a = document.getElementById("alternate").value; // take alternative field UnixTimeStamp value
a = a.slice(0, -3);     // get rid of 3 extra 0's
a = +a + +57000;        // convert to Thai time

Post a Comment for "How To Avoid Time Zone Issues With JQuery Datepicker"