View source code
Display the source code in std/datetime/systime.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.datetime.systime.SysTime.toSimpleString

Converts this SysTime to a string with the format YYYY-Mon-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone).

string toSimpleString() nothrow scope @safe const;

void toSimpleString(W) (
  ref W writer
) const scope
if (isOutputRange!(W, char));

Note that the number of digits in the fractional seconds varies with the number of fractional seconds. It's a maximum of 7 (which would be hnsecs), but only has as many as are necessary to hold the correct value (so no trailing zeroes), and if there are no fractional seconds, then there is no decimal point.

If this SysTime's time zone is LocalTime, then TZ is empty. If its time zone is UTC, then it is "Z". Otherwise, it is the offset from UTC (e.g. +01:00 or -07:00). Note that the offset from UTC is not enough to uniquely identify the time zone.

Time zone offsets will be in the form +HH:MM or -HH:MM.

Parameters

NameDescription
writer A char accepting output range

Returns

A string when not using an output range; void otherwise.

Example

import core.time : msecs, hnsecs;
import std.datetime.date : DateTime;

assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toSimpleString() ==
       "2010-Jul-04 07:06:12");

assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), msecs(24)).toSimpleString() ==
       "1998-Dec-25 02:15:00.024");

assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toSimpleString() ==
       "0000-Jan-05 23:09:59");

assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toSimpleString() ==
        "-0004-Jan-05 00:00:02.052092");

Authors

Jonathan M Davis

License

Boost License 1.0.