Iâ€™ve long had issues working with timezones in PHP, especially when it comes to coping withÂ Daylight Saving TimeÂ – the annoying inconsistent flexibility of shifting local times back and forward an hour for the Summer.
Recently, Iâ€™ve been using theÂ putenvÂ function to hardcode a timezone to an application, eg. for Greenwich Mean Time (GMT):
The problem with this is it doesnâ€™t cater for Summer timezones eg.BSTÂ (for British Summer Time).
I realised this morning that the value can actually be set to one of the manyÂ timezone locationsÂ rather than just a timezone code. Eg:
Using this, you can rely on the server to work out whether you are in Daylight Saving Time or not based on the specified location and current date.
Iâ€™ve implemented this on a CakePHP website (configured in config/bootstrap.php for those who use CakePHP) and it worked straight away.