www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.datetime for month integer

reply dsmith <ds nomail.com> writes:
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?
Jul 18 2011
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Jul 18 2011