Date Formating
codephantom
me at noyb.com
Wed Dec 13 02:34:12 UTC 2017
On Tuesday, 12 December 2017 at 15:56:59 UTC, Vino wrote:
> Hi All,
>
> Request out help on date formatting, I have code which output
> the date and time as below , i we need it without the last few
> numbers.,ie "YYYY-MMM-DD HH:MM:SI"
>
> Output : 2017-Sep-06 16:06:42.7223837
> Required Output : 2017-Sep-06 16:06:42
>
> From,
> Vino.B
just playing with this...
// ----------
module test;
void main()
{
import std.stdio;
writeln( GetFmtDate() ); // e.g: 2017-Dec-13 13:30:23
}
string GetFmtDate()
{
import std.datetime;
import std.ascii : toUpper;
import std.conv : to;
import std.string : format;
auto d = Clock.currTime();
string fmtMonth = toUpper(to!string(d.month)[0]) ~
to!string(d.month)[1..$];
return
format("%04s-%s-%02s %02s:%02s:%02s",
(d.year),
fmtMonth,
(d.day),
(d.hour),
(d.minute),
(d.second)
);
}
// --------------
More information about the Digitalmars-d-learn
mailing list