PHP code example of alex-no / server-time-clock

1. Go to this page and download the library: Download alex-no/server-time-clock library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alex-no / server-time-clock example snippets


use ServerTimeClock\ServerClock;

$clock = new ServerClock([
    'client' => 'WorldTimeApi', // or 'IpGeoLocation', 'TimeApiIo'
    'credentials' => [
        'IpGeoLocation' => 'your-api-key', // optional, depending on the provider
        'WorldTimeApi' => 'your-api-key2',
    ],
    'enable_cache' => true,
    'cache_ttl' => 300, // seconds
    'useMock' => false, // Mosk is usually used for testing.
]);

$now = $clock->now(); // instance of DateTimeImmutable
echo $now->format(DATE_ATOM);

return [
    'client' => 'WorldTimeApi', // Preferred time provider
    'credentials' => [
        'IpGeoLocation' => 'your-api-key',
        'WorldTimeApi' => 'your-api-key2',
    ],
    'enable_cache' => true,
    'cache_ttl' => 300,
];

use ServerTimeClock\ServerClock;

$clock = app(ServerClock::class);
echo $clock->now()->format('c');

'components' => [
    'serverClock' => [
        'class' => \ServerTimeClock\Yii\ServerClockComponent::class,
        'client' => 'WorldTimeApi',  // Preferred time provider
        'credentials' => [
            'IpGeoLocation' => 'your-api-key',
            'WorldTimeApi' => 'your-api-key2',
        ],
        'enableCache' => true,
        'cacheTtl' => 300,
    ],
],

Yii::$app->serverClock->now();