2

I am trying to use jsTimezoneDetect to automatically find the timezone set on the user's computer. Here is the code for the jsTimezoneDetect:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js"></script>
<script>

$(document).ready(function(){
    var tz = jstz.determine();
    var tzname = tz.name();
    $.post("../Includes/timezone.php", {timezone: tzname});
});

I need help as I am not very experienced in either PHP or Javascript. How do I add what the Javascript is finding from the user's computer to a date_defult_timezone_set() in a (example) 'Europe/London' kind of format.

  • What are you trying to achieve that can't be done using *Date.prototoype.timezoneOffset*? The IANA timezone name doesn't tell you the actual offset, or whether the user is on standard or daylight saving time. – RobG Dec 20 '16 at 23:39
  • How do I do that then? –  Dec 21 '16 at 10:47
  • `new Date().timezoneOffset()`, which is minutes to subtract from UTC to get the local time, so +ve for west of Greenwich and -ve for east. The sign is opposite to the ISO 8601 standard and common use, which is +ve for east and -ve for west. – RobG Dec 21 '16 at 22:28
  • @RobG In fact it's better to work with named time zones just because of that: the offset is not hardcoded and works reliably for dates any month and any year. – Álvaro González Dec 27 '16 at 15:59
  • Note that in my comments, *timezoneOffset* should be *getTimezoneOffset*. :-o – RobG Dec 27 '16 at 22:30
  • @ÁlvaroGonzález—it depends on what the OP is trying to do. – RobG Dec 27 '16 at 22:33

0 Answers0