std.datetime for month integer

Jonathan M Davis jmdavisProg at gmx.com
Mon Jul 18 09:14:19 PDT 2011


On Monday 18 July 2011 16:01:06 dsmith wrote:
> Recall that std.date used the following to retrieve a month in integer form
> (0 .. 11):
> 
>   auto Now = std.date.getUTCtime();
>   writeln(std.date.monthFromTime(Now));
> 
> Using std.datetime, the following yields the abbreviated month name:
> 
>   auto Now = Clock.currTime();
>   writefln("%s", Now.month);    // --> jul
> 
> Now, how can std.datetime be used to print the month in integer form?

Cast it to an integer (or use std.conv.to will probably work - it _should_ at 
least; if it doesn't, it needs to be fixed). std.datetime.Month is a named 
enum. So, presumably that's why you're seeing it as a the enum's name. I think 
that that's only happening because you're using it directly in writefln though. 
If you assigned it to a variable first, I think that it would just be a ubyte, 
since that's the type of the Month enum).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list