PHP
$city = "Australia/NSW";
function get_timezone_abre()
{
global $city;
$dateTime = new DateTime();
$dateTime->setTimeZone(new DateTimeZone($city ));
return 'A'.$dateTime->format('T');
}
Result
AEST
Not sure either this will show daylight saving has started, can someone clarify this please?
Looked at this link, what-are-the-standard-timezone-abbreviations.
Can someone suggest a better way to do this (includes daylight saving)?
Add reading material
Australia DST timezone abbreviation incorrect when using date_default_timezone_set
EST
is derived from using older php lib.Australia/NSW is not a valid timezone identifier. Valid timezone identifiers for Australia are:
[299] => Australia/Adelaide
[300] => Australia/Brisbane
[301] => Australia/Broken_Hill
[302] => Australia/Currie
[303] => Australia/Darwin
[304] => Australia/Eucla
[305] => Australia/Hobart
[306] => Australia/Lindeman
[307] => Australia/Lord_Howe
[308] => Australia/Melbourne
[309] => Australia/Perth
[310] => Australia/Sydney
You can find this list by using DateTimeZone::listIdentifiers()
(see reference).
Australia/NSW
is valid but this comment here says it was included for backwards compatibility and could be removed.
This code should do what you need, it considers the daylight savings changes too:
<?php
$city = "Australia/NSW";
$timezone = new DateTimeZone($city);
$date_time = new DateTime('now', $timezone);
echo $date_time->format('T') . PHP_EOL;
echo $date_time->modify('+6 months')->format('T');
This will output:
AEST
AEDT
Demo here: https://eval.in/772564
Try this.
date_default_timezone_set('Europe/Sofia');
echo date_default_timezone_get(); // Europe/Sofia
echo ' => '.date('T'); // => EET