Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does DateTime add a T separator to the timestamp?

Tags:

datetime

perl

My code:

print DateTime->now;

Response:

2012-08-17T20:16:37

Why is there a T? Is there an option I have forgotten?

like image 761
Rijvi Rajib Avatar asked Aug 17 '12 20:08

Rijvi Rajib


People also ask

What does t mean in timestamp?

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).

What is TZ format?

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.

What is ISO date format t?

Note that the "T" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601.

What is the Z at the end of a timestamp?

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.


2 Answers

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").

like image 124
Gabe Avatar answered Sep 19 '22 08:09

Gabe


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(':') }
like image 43
mob Avatar answered Sep 22 '22 08:09

mob