Date formatting in D
aberba via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 8 08:00:26 PST 2017
On Wednesday, 8 March 2017 at 15:46:42 UTC, Adam D. Ruppe wrote:
> On Wednesday, 8 March 2017 at 15:29:11 UTC, aberba wrote:
>> [...]
>
> The PHP function is basically just (translated to D):
>
> string date(string format, time_t timestamp) {
> char[256] buffer;
> auto ret = strftime(buffer.ptr, buffer.ptr,
> toStringz(format), gmtime(×tamp);
> return buffer[0 .. ret].idup;
> }
>
>
> in other words, it is a thin wrapper around the C function.
>
> Let's see, how do we get a time_t out of D's std.datetime?
>
> http://dpldocs.info/locate?q=time_t
>
> The SysTime "toUnixTime" looks good:
>
> http://dpldocs.info/experimental-docs/std.datetime.SysTime.toUnixTime.html
>
>
>
> So an overload might be
>
>
> string date(string format, SysTime time) {
> date(format, time.toUnixTime());
> }
Your docs page is really effective, not pretty though.
More information about the Digitalmars-d-learn
mailing list