Reputation: 933
I have a problem with PHP IMAP timezones.
I have a server that download emails from my users accounts. And than the users can view their email on my website.
I set the php timezone of my server to UTC 0 and now i want that my users see the receiving time of the emails to their timezones. But the problem is the summer time because the timezone change of 1 hour.
Example:
GMail give me an email with received time in UTC (0) at 7:00.
In Italy, the timezone is UTC +1 so i can add 1 hour to this time, then it will be 8:00.
But now in Italy we have the summer timezone so the UTC must be +2 not +1 but not all countries have this. So i ask if exists maybe a online service that can give me the correct offset that i must add to the hour for showing the correct time.
Thank you in advance.
Upvotes: 0
Views: 844
Reputation: 146460
In Italy the time zone swaps between CET and CEST so you cannot hard-code it using names that do not reflect this fact. You need to use geographical identifiers like Europe/Rome
:
<?php
$utc = new DateTimeZone('UTC');
$rome = new DateTimeZone('Europe/Rome');
$winter = new DateTime('2013-12-31', $utc);
$summer = new DateTime('2013-08-31', $utc);
$winter->setTimezone($rome);
$summer->setTimezone($rome);
echo $winter->format('r') . PHP_EOL;
echo $summer->format('r') . PHP_EOL;
Tue, 31 Dec 2013 01:00:00 +0100
Sat, 31 Aug 2013 02:00:00 +0200
Upvotes: 1