I would like to get their timezone with names like \'Asia/Calcutta\' or \'Australia/Darwin\'
I have php installed on myserver and i
This is my first post here but hopefully I can help someone. I felt compelled because this site has helped me a lot. Thanks stackoverflow members!
http://www.pageloom.com/automatic-timezone-detection-with-javascript
From what I understand about this JavaScript code it is very accurate and will be able to return the offset from UST, the corresponding Olson Database timezone name, and handle the daylight savings time issue (ex. -5:00, America/New_york, true).
http://www.php.net/manual/en/timezones.america.php
The above link is just a list of the php supported timezone parameters, which as far as I can tell align with this JavaScript code (I am sure that is beneficial I just don't know why yet I am still writing my code and I am kinda new to php/mysql).
The only hurdle you will face after getting this code working on your html page will likely be getting these values to php and then to mysql if that is what you need. I achieved this by sending these values as a $.post using JQuery. I think this is the easiest way to do it (please someone correct me if I am wrong). I believe the other alternatives are using an AJAX command (more complicated) or cookies(I think?).
After I got the values from the Java-script code to the server (PHP) I stored them as session variables so they would change if the user on my site logged in from a different timezone then usual. However they could easily be saved to the database as well.
If you use the JQuery route this needs to be in the header of the html document where the $.post is being executed.
The most updated timezonedetect script can be found linked on that first url I posted.
//replace this comment with the most updated timezonedetect code from that first link
var timezone = jstz.determine_timezone();
var tzoffset = timezone.offset();
var tzname = timezone.name();
var tzdst = timezone.dst();
$.post("scripts/tzdetect.php", { tzoffset: tzoffset, tzname: tzname, tzdst: tzdst } );
The receiving file in this case tzdetect.php should look like this if you want the data stored as session variables.