PHP code example of namnv609 / timezonedb-php-api

1. Go to this page and download the library: Download namnv609/timezonedb-php-api 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/ */

    

namnv609 / timezonedb-php-api example snippets


use NNV\TimeZoneDB;

$tzDB = new TimeZoneDB(<TimeZoneDB API Key>);

$listTimeZoneParams = [
    "fields" => "countryCode,countryName",
    "country" => "NZ",
    // Other params
];
$tzDB->listTimeZone($listTimeZoneParams);

$getTimeZoneParams = [
    "by" => "zone",
    "zone" => "America/Chicago",
    // Other params
];
$tzDB->getTimeZone($getTimeZoneParams);

$convertTimeZoneParams = [
    "from" => "America/Los_Angeles",
    "to" => "Australia/Sydney",
    "time" => "06/01/2016 03:00PM", // You can use standard DateTime format or Unix time
    // Other params
];
$tzDB->convertTimeZone($convertTimeZoneParams);

$tzDB->listTimeZones();

$tzDB->codeToZones("AQ");

// Result
[
    8 => "Antarctica/Casey",
    9 => "Antarctica/Davis",
    10 => "Antarctica/DumontDUrville",
    11 => "Antarctica/Mawson",
    12 => "Antarctica/McMurdo",
    13 => "Antarctica/Palmer",
    14 => "Antarctica/Rothera",
    15 => "Antarctica/Syowa",
    16 => "Antarctica/Troll",
    17 => "Antarctica/Vostok",
]


$tzDB->countryToZones("Vietnam");

// Result
[
    418 => "Asia/Ho_Chi_Minh",
]

$tzDB->zoneToCode("Asia/Ho_Chi_Minh");

// Result
"VN"

$tzDB->zoneToCountry("Asia/Ho_Chi_Minh");

// Result
"Vietnam"