Get current date and time with std.datetime

Zekereth via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 1 08:28:04 PDT 2016


On Thursday, 30 June 2016 at 21:18:22 UTC, Luke Picardo wrote:
>
> Why is it so hard to simply get the current date and time 
> formatted properly in a string?
>
> There are no examples of this in your documentation yet this is 
> probably one of the most used cases.

To get the current time, use Clock.currTime. It will return the 
current time as a SysTime. To print it, toString is sufficient, 
but if using toISOString, toISOExtString, or toSimpleString, use 
the corresponding fromISOString, fromISOExtString, or 
fromSimpleString to create a SysTime from the string.

auto currentTime = Clock.currTime();
auto timeString = currentTime.toISOExtString();
auto restoredTime = SysTime.fromISOExtString(timeString);


More information about the Digitalmars-d-learn mailing list