print yyyy-mm-dd

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 24 03:00:40 PST 2014


On Monday, November 24, 2014 10:38:55 Suliman via Digitalmars-d-learn wrote:
> And could anybody explain me how the cast is work. How to
> understand which types to which may be casted?

Look at the documentation for opCast. That's how the casting is done. But
what it comes down to is

SysTime -> DateTime, Date, or TimeOfDay
DateTime -> Date or TimeOfDay

Those are the conversions which lose information, so they can be done via
casts, whereas the conversions that would increase the amount of information
in the type require using a constructor, because you have to use information
from multiple objects to be able to create the new object. e.g.

auto dt = DateTime(date, tod);

The primary reason to cast a SysTime to a Date prior to calling
toISOExtString on it is to strip off the time portion, but slicing the
result as uri suggested works too (though it's probably a tad less efficient
due to the time spent creating the portion of the string that isn't even
used).

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list