I'm running into what seems to be a common problem of using a javascript datepicker to display and allow users to select dates from a calendar of available schedule dates for room reservations.
The browser's timezone conversion means that these dates are always off by some margin, so that often when displaying a reserved date to the user, the date will fall on "tomorrow" to the viewer, when the server (the timezone local to the asset or room as stored in the DB) shows them as "today".
I would like the user's browser to ignore the javascript date conversion and just use the actual datetime that is passed in by the database.
However, this even happens on a really simple example like this:
var date = '2013-02-05';
var newdate = new Date(date);
console.log(newdate); // Mon Feb 04 2013 16:00:00 GMT-0800 (PST)
It appears that the date
variable is assumed by the browser to be GMT, and when I create a javascript date object from it, it converts that GMT time to my local time.
Is the best practice in this case to use GMT dates in the database, and set the site's local time offset as a variable in the javascript, which can then be used to offset the dates displayed to the end user, and again offset the dates received from the end user for insertion into the database?
This is confusing since there's so many potential pitfalls-- the PHP locale, mysql locale, or browser's locale could all factor into it and mess up the final date. Any advice on ensuring a consistent date value appreciated!