www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - what's the best way to convert a sysTime to local machine's time

reply mw <mingwu gmail.com> writes:
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.
Sep 24 2020
next sibling parent reply James Blachly <james.blachly gmail.com> writes:
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].
Sep 24 2020
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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
Sep 24 2020
prev sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
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
Sep 25 2020