Search code examples
datetimedutc

How to get current UTC 0 time with D?


I need to get current UTC 0 time.

I had read Phobos datetime documentation and look like I need this part:

Clock.currTime will return the current time as a SysTime. To convert a SysTime to a Date or DateTime, simply cast it. To convert a Date or DateTime to a SysTime, use SysTime's constructor, and pass in the intended time zone with it (or don't pass in a TimeZone, and the local time zone will be used).

If I right understand I need 1. Get current SysTime. 2. Convert its to DateTime 3. Convert result DateTime to get LocalTime (UTC?).

Could anybody give me any example how to get current UTC 0 time?


Solution

  • You can pass a TimeZone argument to Clock.currTime

    So instead you can just call auto time = Clock.currTime(UTC());

    This will be a SysTime with the current UTC time