Thread overview
print yyyy-mm-dd
Nov 20, 2014
Suliman
Nov 20, 2014
MrSmith
Nov 20, 2014
uri
Nov 24, 2014
Suliman
Nov 24, 2014
Suliman
Nov 24, 2014
Jonathan M Davis
Nov 24, 2014
Jonathan M Davis
November 20, 2014
I can't understand how to get date in format yyyy-MM-dd from Clock.currTime
auto time = Clock.currTime;

And what next? Could anybody give any examples?
November 20, 2014
On Thursday, 20 November 2014 at 13:50:49 UTC, Suliman wrote:
> I can't understand how to get date in format yyyy-MM-dd from Clock.currTime
> auto time = Clock.currTime;
>
> And what next? Could anybody give any examples?

http://dpaste.dzfl.pl/73c0438f9d1e

currTime returns SysTime;
You can then cast is to Date.
And Date has toISOExtString which converts Date to a string with the format YYYY-MM-DD.
November 20, 2014
On Thursday, 20 November 2014 at 20:38:08 UTC, MrSmith wrote:
> On Thursday, 20 November 2014 at 13:50:49 UTC, Suliman wrote:
>> I can't understand how to get date in format yyyy-MM-dd from Clock.currTime
>> auto time = Clock.currTime;
>>
>> And what next? Could anybody give any examples?
>
> http://dpaste.dzfl.pl/73c0438f9d1e
>
> currTime returns SysTime;
> You can then cast is to Date.
> And Date has toISOExtString which converts Date to a string with the format YYYY-MM-DD.

There's no need to cast, SysTime supports conversion to string

http://dlang.org/library/std/datetime/SysTime.toISOExtString.html
http://dlang.org/library/std/datetime/SysTime.toISOString.html

If you want just the YYYY-MM-DD slice it

Clock.currTime.toISOExtString[0..10].writeln;
Clock.currTime.toISOString[0..8].writeln;

Cheers,
uri

November 24, 2014
Is there any way to set separator? For example I want use '/' or ':'?
November 24, 2014
And could anybody explain me how the cast is work. How to understand which types to which may be casted?
November 24, 2014
On Monday, November 24, 2014 10:33:16 Suliman via Digitalmars-d-learn wrote:
> Is there any way to set separator? For example I want use '/' or ':'?

No. toISOString and toISOExtString support the ISO and Extended ISO formats from the ISO standard, and std.datetime does not currently support custom date/time string formatting (though it's on the todo list). The only non-standard format that it currently suports is Boost's "simple" time via toSimpleString, and it probably shouldn't even be there, since it just confuses things without adding any real, useful functionality. Custom date/time string formatting is what's really needed for non-standard representations, especially because everyone has a different way that they want to represent the time. However, most code really should use toISOExtString, since it's standard and reasonably readable (e.g. 2014-11-24T02:53:12 as opposed to the non-extended ISO format of 20141124T025312).

- Jonathan M Davis

November 24, 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