World clock with DST support and server synchronization

I want to include the JavaScript world clock, such as http://www.dynamicdrive.com/dynamicindex6/localtime.htm in my homepage, but I do not want to change it every time the DST changes for the time zone. Is it possible to automatically synchronize it with the official time server so that I can display the current time for different places in real time and without any changes after DST?

+3
source share
1 answer

Use the standard datefeature with date_default_timezone_set.

$timezones = array("Australia/Brisbane", "America/New York", "Europe/London");

foreach ($timezones as $tz) {
    date_default_timezone_set($tz);
    echo "The time in $tz is: " . date('r');
}

It processes all daily savings and everything for you.

: http://www.php.net/manual/en/timezones.php


: Javascript:

  • , PHP , , date('Z'), UTC. JSON -, Javascript:

    var offsets = {
        'Brisbane' : 36000,
        'Sydney'   : 42000,
        'London'   : 0
    };
    
  • , .

    for (var city in offsets) {
        var d = new Date();
        d.setTime(d.getTime() + offsets[city] * 1000);
        alert('The time in ' + city + ' is ' + d.toUTCString());
    }
    
  • , , setInterval

: , , - ( DST). , , , , .

+1

Source: https://habr.com/ru/post/1729735/


All Articles