How to fix date format?

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 25 23:55:01 PDT 2017


On Wednesday, 26 April 2017 at 05:21:32 UTC, Jonathan M Davis 
wrote:
> On Wednesday, April 26, 2017 04:02:12 Suliman via 
> Digitalmars-d-learn wrote:
>> I tried to do:
>>
>> writeln(DateTime.toISOExtString(DateTime.fromSimpleString(point[1].coerce!
>> string)));
>>
>> But got error:
>>
>> Error: function std.datetime.DateTime.toISOExtString () const 
>> is
>> not callable using argument types (DateTime)
>> Error: function database.Database.getSingleTrackInfo no return
>> exp; or assert(0); at end of function
>
> toISOExtString is a normal member function on DateTime, not a 
> static member function. If point[1].coerce!string is giving you 
> a string in Boost's "simple time" format (e.g. "2016-Jan-04 
> 12:19:17"), then 
> DateTime.fromSimpleString(point[1].coerce!string) will give you 
> a DateTime. Then if you called toISOExtString() on that, e.g.
>
> DateTime dt = DateTime.fromSimpleString(point[1].coerce!string);
> string str = dt.toISOExtString();
>
> then the string would be in the ISO extended format (e.g. 
> "2016-01-04T12:19:17"). If you then wanted that in the format 
> "2016-01-04 12:19:17", then you could just replace the 'T' with 
> ' ', e.g.
>
> DateTime dt = DateTime.fromSimpleString(point[1].coerce!string);
> string str = dt.toISOExtString().replace("T", " ");
>
> And if you have "2016-01-04 12:19:17", and you want to convert 
> that to the Boost simple time format, you could do
>
> DateTime dt = DateTime.fromISOExtString(str.replace(" ", "T"))
> auto simpleStr = dt.toSimpleString();
>
> Hopefully, that helps.
>
> - Jonathan M Davis

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();


More information about the Digitalmars-d-learn mailing list