Web Analytics Made Easy -
StatCounter Time Timezones - CodingForum

Announcement

Collapse
No announcement yet.

Time Timezones

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Time Timezones

    I have a script that shows Local time for different cities at the same time. The code is (for example):
    PHP Code:
    <?php
    // Time in Paris
    date_default_timezone_set('Europe/Paris');
    echo(
    date("h:i:s") . "<br />");

    // Time in Athens
    date_default_timezone_set('Europe/Athens');
    echo(
    date("h:i:s") . "<br />");

    // Time in London
    date_default_timezone_set('Europe/London');
    echo(
    date("h:i:s") . "<br />");

    // Time in New York
    date_default_timezone_set('America/New_York');
    echo(
    date("h:i:s") . "<br />");

    // Time in Chicago
    date_default_timezone_set('America/Chicago');
    echo(
    date("h:i:s") . "<br />");
    ?>
    The problem is that the list (of World Clocks) is long, so adding date_default_timezone_set on every line isn't practical...
    There is a way to manually add hours to every clock, but daylight savings change....

    So is there is a way (other than manually adding hours) to get the time for every timezone (city) without always using date_default_timezone_set ?

    Any Suggestion Will Be Helpful

  • #2
    Yes.. using a loop and an array of timezones.

    PHP Code:
    $TimeZones[] = 'Europe/London';
    $TimeZones[] = 'Europe/Paris';
    //Etc

    foreach ($TimeZones as $Key => $Value)
       {
       
    date_default_timezone_set($Value); 
       echo(
    date("h:i:s") . "<br />"); 
       } 
    "Tango says double quotes with a single ( ' ) quote in the middle"
    '$Name says single quotes with a double ( " ) quote in the middle'
    "Tango says double quotes ( \" ) must escape a double quote"
    '$Name single quotes ( \' ) must escape a single quote'

    Comment

    Working...
    X