Re: Time Zone Calculations
| From: | B. Aerts | Date: | Mon, 18 Nov 2013 06:53:01 +0000 |
| Subject: | Re: Time Zone Calculations | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-322471@lists.php.net to get a copy of this message | ||
On 18/11/13 02:25, Ron Piggott wrote:
Hi EveryoneHi Ron, how exactly do add the number of days ? Do you use http://be.php.net/manual/en/datetime.add.php ? Changing from GMT to Eastern is the wrong option: DST does not apply to GMT - it applies to the offset between GMT and local time. I.e. CEST is GMT+1 in winter, and GMT+2 in summer. In fact, best to do is change from local time to GMT, then shift days, and come back to local time. Let me know if it works. BertThe result of the code below (Converting the time from GMT to Eastern , Then adding 561 Days and converting back to GMT) is giving me the result: 2013-11-18 14:32:00 I was expecting an hour earlier (2013-11-18 13:32:00) Is there something I am doing wrong?- I am trying to calculate 561 days in the future, but keeping the same time. - The reason I thought about converting from GMT to Eastern and back to GMT was because I wondered if Daylight Savings Time was the issue. Ron <?php $occurance_date = '2012-05-06 13:32:00'; $dt = new \DateTime( date('Y-m-d H:i:s' , strtotime( $occurance_date ) ) , new \DateTimeZone( 'GMT' ) ); $dt->setTimezone(new \DateTimeZone( "Canada/Eastern" )); $dt->modify('+561 days'); $dt->setTimezone(new \DateTimeZone( 'GMT' )); $revised_occurance_date = $dt->format('Y-m-d H:i:s'); ?> Ron Piggott www.TheVerseOfTheDay.info