Function std.datetime.systime.SysTime.toISOString
Converts this SysTime
to a string with the format
YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds and TZ is time
zone).
string toISOString() nothrow @safe const;
void toISOString(W)
(
ref W writer
) const
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. +0100 or -0700). Note that the offset from UTC is not enough
to uniquely identify the time zone.
Time zone offsets will be in the form +HHMM or -HHMM.
Warning:
Previously, toISOString did the same as toISOExtString
and
generated +HH:MM or -HH:MM for the time zone when it was not
LocalTime
or
UTC
, which is not in conformance with
ISO 8601 for the non-extended string format. This has now been
fixed. However, for now, fromISOString will continue to accept the
extended format for the time zone so that any code which has been
writing out the result of toISOString to read in later will continue
to work. The current behavior will be kept until July 2019 at which
point, fromISOString will be fixed to be standards compliant.
Parameters
Name | Description |
---|---|
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)) .toISOString() ==
"20100704T070612");
assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), msecs(24)) .toISOString() ==
"19981225T021500.024");
assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)) .toISOString() ==
"00000105T230959");
assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)) .toISOString() ==
"-00040105T000002.052092");