Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: UTC to local time, allowing for US daylight savings time. Date: Mon, 14 Mar 2022 16:18:52 +0100 Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net ieu1PKL8iOtbxkB7/IYt3gmEBPY/jVhDZD0SHsLbtf+ClVu5Xw Cancel-Lock: sha1:+NTLLBTrwzBVBbvBNTK6V5VuXc4= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US-large In-Reply-To: Xref: csiph.com comp.lang.php:18887 On 14/03/2022 15.20, bill wrote: > I have a UTC time and I need to display it as local time (always US > Eastern time). > > I could check to see if we are now in standard or daylight time and then > add the appropriate number of hours, but it seems there should be an > easier way with php automagically doing the proper conversion. > > Any suggestions? something like this? date_default_timezone_set('UTC'); utc_datetime = '2008-08-03 12:35:23'; $datetime = new DateTime(utc_datetime); $ny_time = new DateTimeZone('America/New_York'); $datetime->setTimezone($ny_time); echo $datetime->format('Y-m-d H:i:s'); You have also possibility to use javascript in the UI, then you could quite simply get to the users local time without having a config. -- //Aho