My code:
print DateTime->now;
Response:
2012-08-17T20:16:37
Why is there a T? Is there an option I have forgotten?
The T doesn't really stand for anything. It is just the separator that the ISO 8601 combined date-time format requires. You can read it as an abbreviation for Time. The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
The tz database is published as a set of text files which list the rules and zone transitions in a human-readable format. For use, these text files are compiled into a set of platform-independent binary files—one per time zone.
Note that the "T" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601.
The Z stands for the zero UTC offset. If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset.
The T
is just a standard (ISO 8601) way to delimit the time. To use a different format, consider using strftime
or format_cldr
.
For example, to have a space instead, use DateTime->now->format_cldr("YYYY-MM-dd hh:mm:ss")
.
Stringifying a DateTime
object uses the ISO 8601 format unless you have specified a formatter in the constructor. See Formatters and Stringification in the docs.
The iso8601
method is:
sub iso8601 { join 'T', $_[0]->ymd('-'), $_[0]->hms(':') }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With