Convert UTC timezone into AWST timezone in ZF2

I am trying to convert the timezone with below piece of code which is working fine except AWST timezone.

$date = time();
$timeZone = "AWST";
$dt = new \DateTime();
$dt->setTimestamp($date);
$dt->setTimezone(new \DateTimeZone($timeZone));
echo  $dt->format('Y/m/d H:i:s');

If i put $timeZone = "UTC" or something that is working fine. Experts can help me out from this.

Jon Skeet
people
quotationmark

I suspect the problem is that you need to specify an IANA time zone ID rather than just an abbreviation. Time zone abbreviations are really problematic for various reasons:

  • They usually indicate "half" a time zone; "Europe/London" switches between "GMT" and "BST" for example
  • They can be ambiguous - for example, "CST" means different things in different places (and at different points in history)
  • Different places switch between different abbreviations at different times of year.

If you can get the right time zone ID for the place you care about, that should give you the right local time throughout history, assuming the time zone data is complete and accurate.

In your case, I believe you want the Australia/Perth time zone. Try this:

$timeZone = "Australia/Perth"

people

See more on this question at Stackoverflow