On Saturday, 29 March 2014 at 05:01:14 UTC, Gary Miller wrote:
I've been reading through and trying various code fragments to pull the system date/time in and format it as a string for display on the console.

I only need it down to the second and from my current machine so I don't need to use any of the more accurate clocks used for benchmarking right now.

This is the easiest way i know.

import std.stdio;
import std.datetime;

void main(string[] args)
{
        writeln(Clock.currTime.toLocalTime.toSimpleString);
}

It would be nice if all the primitive datatypes had a consistent toString cast or function but since I'm not seeing those I guess writeFormatted must be the preferred way of getting values into string format.

See std.conv and the 'to' function.

data.to!(string)
data.to!(int)
etc...

http://dlang.org/phobos/std_conv.html#.to

Reply via email to