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

    From Lew Pitcher@21:1/5 to bill on Mon Mar 14 15:10:24 2022
    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"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill@21:1/5 to All on Mon Mar 14 10:20:01 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to bill on Mon Mar 14 16:18:52 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to bill on Tue Mar 15 16:46:23 2022
    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"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill@21:1/5 to Lew Pitcher on Tue Mar 15 12:39:01 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill@21:1/5 to Lew Pitcher on Wed Mar 16 07:06:17 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill@21:1/5 to J.O. Aho on Wed Mar 16 07:05:43 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)