Thread overview
what's the best way to convert a sysTime to local machine's time (zone)?
Sep 24, 2020
mw
Sep 25, 2020
James Blachly
Sep 25, 2020
H. S. Teoh
Sep 25, 2020
Ferhat Kurtulmuş
September 24, 2020
Hi,

I'm just wondering what's the best way to convert sysTime to local machine's time (zone)?

Is there any library function does this already?


https://dlang.org/phobos/std_datetime_systime.html#SysTime

(The time in SysTime is kept internally in hnsecs from midnight, January 1st, 1 A.D. UTC.)

Thanks.


September 24, 2020
On 9/24/20 6:22 PM, mw wrote:
> Hi,
> 
> I'm just wondering what's the best way to convert sysTime to local machine's time (zone)?
> 
> Is there any library function does this already?
> 
> 
> https://dlang.org/phobos/std_datetime_systime.html#SysTime
> 
> (The time in SysTime is kept internally in hnsecs from midnight, January 1st, 1 A.D. UTC.)
> 
> Thanks.

It is definitely not easy to find.

https://dlang.org/phobos/std_datetime_systime.html#.SysTime.timezone

SysTime struct contains member fn timezone which will return the current settings' TZ ; you can then apply this TZ to other functions in std.datetime to transform datetimes to the TZ [of your choice].
September 24, 2020
On Thu, Sep 24, 2020 at 08:36:38PM -0400, James Blachly via Digitalmars-d-learn wrote:
> On 9/24/20 6:22 PM, mw wrote:
[...]
> > I'm just wondering what's the best way to convert sysTime to local
> > machine's time (zone)?
[...]
> It is definitely not easy to find.
> 
> https://dlang.org/phobos/std_datetime_systime.html#.SysTime.timezone
> 
> SysTime struct contains member fn timezone which will return the current settings' TZ ; you can then apply this TZ to other functions in std.datetime to transform datetimes to the TZ [of your choice].

Seriously, this should be put in the std.datetime docs on the first page. It's a common operation that should not require reading through multiple non-trivially long doc pages and piecing it together yourself.

Please file a bug against the docs if there isn't already one.


T

-- 
Nearly all men can stand adversity, but if you want to test a man's character, give him power. -- Abraham Lincoln
September 25, 2020
On Thursday, 24 September 2020 at 22:22:13 UTC, mw wrote:
> Hi,
>
> I'm just wondering what's the best way to convert sysTime to local machine's time (zone)?
>
> Is there any library function does this already?
>
>
> https://dlang.org/phobos/std_datetime_systime.html#SysTime
>
> (The time in SysTime is kept internally in hnsecs from midnight, January 1st, 1 A.D. UTC.)
>
> Thanks.

This library may help:
https://code.dlang.org/packages/hunt-time