Formatted date
Jonathan M Davis
jmdavisProg at gmx.com
Thu Nov 3 17:51:14 PDT 2011
On Thursday, November 03, 2011 16:58 Lishaak Bystroushaak wrote:
> Hello.
>
> Is there any way how to format date with formating strings? Something
> like strftime in python;
> http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior
Not currently. SysTime (and the other time point types in std.datetime) have
functions for converting them to specific ISO standards but not custom
formatting strings. That's in the works but hasn't been completed yet.
In the meantime, you can get a time_t from a SysTime using its unixTime
property and pass that to C's strftime (though be warned that it risks being
an hour off on Windows, since for some bizarre reason Windows applies DST to
UTC such that time_t on Windows isn't actually guaranteed to always be the
number of seconds since midnight January 1st, 1970 in UTC).
Another alternative is that someone ported the deprecated std.dateparse (which
worked with the deprecated and very broken std.date) to use SysTime, and you
can use that: https://gist.github.com/1283011
toCustomString will be added to SysTime and the other time point types in
std.datetime, but its design hasn't been completed sorted out yet, let alone
fully implemented, so it's in the works, but it could be a little while before
it makes it into Phobos.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list