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


Groups > comp.lang.php > #18885 > unrolled thread

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

Started bybill <william@TechServSys.com>
First post2022-03-14 10:20 -0400
Last post2022-03-16 07:05 -0400
Articles 7 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  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

#18885 — UTC to local time, allowing for US daylight savings time.

Frombill <william@TechServSys.com>
Date2022-03-14 10:20 -0400
SubjectUTC to local time, allowing for US daylight savings time.
Message-ID<t0niui$a4e$1@gioia.aioe.org>
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?

Thanks in advance,

-bill

[toc] | [next] | [standalone]


#18886

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2022-03-14 15:10 +0000
Message-ID<t0nlt0$fd8$1@dont-email.me>
In reply to#18885
On Mon, 14 Mar 2022 10:20:01 -0400, 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?

One possibility (which may be overkill for you; you decide) would
be to change the "date.timezone" value in php.ini to name EST5EDT
rather than the default UTC
  [Date]
  ; Defines the default timezone used by the date functions
  ; http://php.net/date.timezone
  date.timezone = EST5EDT         ; override UTC default

From there, you can use the php date functions, and they will
reflect EST5EDT dates and times

HTH

-- 
Lew Pitcher
"In Skills, We Trust"

[toc] | [prev] | [next] | [standalone]


#18888

Frombill <william@TechServSys.com>
Date2022-03-15 12:39 -0400
Message-ID<t0qff5$1qd$1@gioia.aioe.org>
In reply to#18886
On 3/14/2022 11:10 AM, Lew Pitcher wrote:
> On Mon, 14 Mar 2022 10:20:01 -0400, 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?
> 
> One possibility (which may be overkill for you; you decide) would
> be to change the "date.timezone" value in php.ini to name EST5EDT
> rather than the default UTC
>    [Date]
>    ; Defines the default timezone used by the date functions
>    ; http://php.net/date.timezone
>    date.timezone = EST5EDT         ; override UTC default
> 
>  From there, you can use the php date functions, and they will
> reflect EST5EDT dates and times
> 
> HTH
> 
  I wasn't clear enough:  I have a variable (from an ical string) 
containing the appointment date/time as UTC.  In order to display 
this I need to convert it to local  (12 hr) time.
Thanks bill

[toc] | [prev] | [next] | [standalone]


#18889

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2022-03-15 16:46 +0000
Message-ID<t0qfsv$9bc$1@dont-email.me>
In reply to#18888
On Tue, 15 Mar 2022 12:39:01 -0400, bill wrote:

> On 3/14/2022 11:10 AM, Lew Pitcher wrote:
>> On Mon, 14 Mar 2022 10:20:01 -0400, 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?
>> 
>> One possibility (which may be overkill for you; you decide) would
>> be to change the "date.timezone" value in php.ini to name EST5EDT
>> rather than the default UTC
>>    [Date]
>>    ; Defines the default timezone used by the date functions
>>    ; http://php.net/date.timezone
>>    date.timezone = EST5EDT         ; override UTC default
>> 
>>  From there, you can use the php date functions, and they will
>> reflect EST5EDT dates and times
>> 
>> HTH
>> 
>   I wasn't clear enough:  I have a variable (from an ical string) 
> containing the appointment date/time as UTC.  In order to display 
> this I need to convert it to local  (12 hr) time.
> Thanks bill

Then, J Aho's advice is what you want. See his response upthread.

-- 
Lew Pitcher
"In Skills, We Trust"

[toc] | [prev] | [next] | [standalone]


#18891

Frombill <william@TechServSys.com>
Date2022-03-16 07:06 -0400
Message-ID<t0sgb9$1efu$2@gioia.aioe.org>
In reply to#18889
On 3/15/2022 12:46 PM, Lew Pitcher wrote:
> On Tue, 15 Mar 2022 12:39:01 -0400, bill wrote:
> 
>> On 3/14/2022 11:10 AM, Lew Pitcher wrote:
>>> On Mon, 14 Mar 2022 10:20:01 -0400, 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?
>>>
>>> One possibility (which may be overkill for you; you decide) would
>>> be to change the "date.timezone" value in php.ini to name EST5EDT
>>> rather than the default UTC
>>>     [Date]
>>>     ; Defines the default timezone used by the date functions
>>>     ; http://php.net/date.timezone
>>>     date.timezone = EST5EDT         ; override UTC default
>>>
>>>   From there, you can use the php date functions, and they will
>>> reflect EST5EDT dates and times
>>>
>>> HTH
>>>
>>    I wasn't clear enough:  I have a variable (from an ical string)
>> containing the appointment date/time as UTC.  In order to display
>> this I need to convert it to local  (12 hr) time.
>> Thanks bill
> 
> Then, J Aho's advice is what you want. See his response upthread.
> 

I did that, thanks.
-bill

[toc] | [prev] | [next] | [standalone]


#18887

From"J.O. Aho" <user@example.net>
Date2022-03-14 16:18 +0100
Message-ID<j994msF7u12U1@mid.individual.net>
In reply to#18885
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

[toc] | [prev] | [next] | [standalone]


#18890

Frombill <william@TechServSys.com>
Date2022-03-16 07:05 -0400
Message-ID<t0sga7$1efu$1@gioia.aioe.org>
In reply to#18887
On 3/14/2022 11:18 AM, J.O. Aho wrote:
> 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.
> 
> 
That works.  Thank you very much.
-bill

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web