print yyyy-mm-dd

uri via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 20 14:25:30 PST 2014


On Thursday, 20 November 2014 at 20:38:08 UTC, MrSmith wrote:
> On Thursday, 20 November 2014 at 13:50:49 UTC, Suliman wrote:
>> I can't understand how to get date in format yyyy-MM-dd from 
>> Clock.currTime
>> auto time = Clock.currTime;
>>
>> And what next? Could anybody give any examples?
>
> http://dpaste.dzfl.pl/73c0438f9d1e
>
> currTime returns SysTime;
> You can then cast is to Date.
> And Date has toISOExtString which converts Date to a string 
> with the format YYYY-MM-DD.

There's no need to cast, SysTime supports conversion to string

http://dlang.org/library/std/datetime/SysTime.toISOExtString.html
http://dlang.org/library/std/datetime/SysTime.toISOString.html

If you want just the YYYY-MM-DD slice it

Clock.currTime.toISOExtString[0..10].writeln;
Clock.currTime.toISOString[0..8].writeln;

Cheers,
uri



More information about the Digitalmars-d-learn mailing list