Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762

    Getting the off-set hour between two timezone date

    Hello,

    I am trying to write a simple script that will workout the off-set in hour, between 2 different timezone.

    This is how i attempted it :

    PHP Code:
    <?php

    $new_tz 
    'America/Toronto'// Based on http://uk3.php.net/manual/en/timezones.america.php

    $current_hour date('h');
    date_default_timezone_set($new_tz); // Based on http://uk3.php.net/manual/en/function.date-default-timezone-set.php
    $new_hour date('h');

    echo 
    'Hour Difference : '. ($current_hour $new_hour);

    ?>
    I ran this script on my local machine (which is in the UK, GMT Timezone). The result i expected to see was -5, because 'America/Toronto' is GMT -5, however, when i ran the script, it outputted -7 (which is wrong).

    Where im i going wrong with this?

  2. #2
    Join Date
    Dec 2002
    Location
    NY, NY
    Posts
    3,975
    Just a thought, if the the time isnt in 24 hour time.. wouldnt you have to do some sort of date_subtract?

    like if it was 12 and 5,... 12-5 = 7
    but it's really 5 hours

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •