How to fix date format?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 26 00:07:25 PDT 2017


On Wednesday, April 26, 2017 06:55:01 Suliman via Digitalmars-d-learn wrote:
> Thanks! That's work!
>
> But why I can't do it in single line like:
> string dt =
> DateTime.toISOExtString(DateTime.fromSimpleString(point[1].coerce!string))
> ; "Error: function std.datetime.DateTime.toISOExtString () const is not
> callable using argument types (DateTime)"
>
> And should do:
>
> DateTime dt = DateTime.fromSimpleString(point[1].coerce!string);
> string str = dt.toISOExtString();

You can do it in a single line. I just split it up so that it fit better in
the limited line length of an e-mail, and because it was clearer with the
types. The problem is that you're calling toISOExtString incorrectly. The
from*String functions are static functions, but the to*String functions are
normal member functions. You don't pass a DateTime to toISOExtString. You
just call it on the DateTime object. So, if you want one line, you end up
with something like

auto str = DateTime.fromSimpleString(point[1].coerce!string).
           toISOExtString().replace("T", " ");

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list