time_t to simple date string conversion

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 5 14:40:12 PDT 2011


On Tue, 05 Apr 2011 17:24:11 -0400, Kai Meyer <kai at unixlords.com> wrote:

> I'm reading documentation on std.datetime, and it appears there are  
> added features that I don't have in 2.51 (Linux). Did features like  
> 'SysTime' get added after 2.51?
>
> Does anybody have a one-liner to convert a time_t to a date string that  
> should work for me?

auto t = time();
auto systime = SystemTime(unixTimeToStdTime(t)); // to system time

 from there, you have many options to create the right string.  You can  
start with just writing it (via toString):

writeln(systime);

There's also:

http://www.digitalmars.com/d/2.0/phobos/std_datetime.html#toSimpleString
http://www.digitalmars.com/d/2.0/phobos/std_datetime.html#toISOString
http://www.digitalmars.com/d/2.0/phobos/std_datetime.html#toISOExtendedString

and doing it directly:

writefln("%s/%s/%s", t.month, t.day, t.year);

Don't see a way to print the month in text format, but maybe I'm  
overlooking it.

-Steve


More information about the Digitalmars-d-learn mailing list