Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18887

Re: UTC to local time, allowing for US daylight savings time.

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: UTC to local time, allowing for US daylight savings time.
Date 2022-03-14 16:18 +0100
Message-ID <j994msF7u12U1@mid.individual.net> (permalink)
References <t0niui$a4e$1@gioia.aioe.org>

Show all headers | View raw


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

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

UTC to local time, allowing for US daylight savings time. bill <william@TechServSys.com> - 2022-03-14 10:20 -0400
  Re: UTC to local time, allowing for US daylight savings time. Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-03-14 15:10 +0000
    Re: UTC to local time, allowing for US daylight savings time. bill <william@TechServSys.com> - 2022-03-15 12:39 -0400
      Re: UTC to local time, allowing for US daylight savings time. Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-03-15 16:46 +0000
        Re: UTC to local time, allowing for US daylight savings time. bill <william@TechServSys.com> - 2022-03-16 07:06 -0400
  Re: UTC to local time, allowing for US daylight savings time. "J.O. Aho" <user@example.net> - 2022-03-14 16:18 +0100
    Re: UTC to local time, allowing for US daylight savings time. bill <william@TechServSys.com> - 2022-03-16 07:05 -0400

csiph-web