getting timezoneoffset using js in php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adrian Parker

    #1

    getting timezoneoffset using js in php

    I have a php page which uses checks to see if the tz variable is in the
    argument list.. if not, it recalls the page using javascript with the added
    tz argument.. if I run it locally here in the UK, the tz is set to 0 which
    is correct. If I run it on a US server, it initially returns -1, but in IE
    if I do a ctrl-refresh, it correctly gets it as 0.

    Any ideas ?

    <?php
    if (!isset($_GET['tz'])) print "
    <script type=\"text/javascript\">
    now = new Date();
    window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + (now.getTimezon eOffset() /
    60);
    </script>";



  • Grant Wagner

    #2
    Re: getting timezoneoffset using js in php

    Adrian Parker wrote:
    [color=blue]
    > I have a php page which uses checks to see if the tz variable is in the
    > argument list.. if not, it recalls the page using javascript with the added
    > tz argument.. if I run it locally here in the UK, the tz is set to 0 which
    > is correct. If I run it on a US server, it initially returns -1, but in IE
    > if I do a ctrl-refresh, it correctly gets it as 0.
    >
    > Any ideas ?
    >
    > <?php
    > if (!isset($_GET['tz'])) print "
    > <script type=\"text/javascript\">
    > now = new Date();
    > window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + (now.getTimezon eOffset() /
    > 60);
    > </script>";[/color]

    --test.php--

    <?php
    if (!isset($_GET['tz'])) print "
    <script type=\"text/javascript\">
    now = new Date();
    window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + (now.getTimezon eOffset() /
    60);
    </script>";

    print $_GET['tz'];
    ?>

    Loaded from Apache/1.3.31 (Unix) mod_ssl/2.8.17 OpenSSL/0.9.7d PHP/4.3.9

    Loaded into IE 6.0.2800 (pre Windows XP Service Pack 2) and IE 6.0.2900 (Windows
    XP Service Pack 2), as well as Mozilla Firefox 0.10.1 (1.0PR) all display "6"
    (I'm currently in CDT - Central Daylight Savings Time). So it appears to be
    working correctly. You can streamline the JavaScript a bit by making it:

    <script type=\"text/javascript\">
    window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + ((new
    Date()).getTime zoneOffset() / 60);
    </script>

    But that shouldn't affect the result.

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Dr John Stockton

      #3
      Re: getting timezoneoffset using js in php

      JRS: In article <4187FFC5.2BC1C 98B@agricoreuni ted.com>, dated Tue, 2
      Nov 2004 21:41:09, seen in news:comp.lang. javascript, Grant Wagner
      <gwagner@agrico reunited.com> posted :[color=blue]
      >
      >Loaded into IE 6.0.2800 (pre Windows XP Service Pack 2) and IE 6.0.2900 (Windows
      >XP Service Pack 2), as well as Mozilla Firefox 0.10.1 (1.0PR) all display "6"
      >(I'm currently in CDT - Central Daylight Savings Time). So it appears to be
      >working correctly. You can streamline the JavaScript a bit by making it:
      >
      ><script type=\"text/javascript\">
      >window.locatio n.href=\"$_SERV ER[PHP_SELF]?tz=\" + ((new
      >Date()).getTim ezoneOffset() / 60);
      ></script>
      >
      >But that shouldn't affect the result.[/color]

      I see possible difficulties if the code is executed with settings for
      Newfoundland, India, etc., where getTimezoneOffs et()/60 is not integer.
      And, indeed, where it is negative.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
      Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
      PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
      Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

      Comment

      Working...