|Perl Language Reference Manual|
by Larry Wall and others
Paperback (6"x9"), 724 pages
RRP £29.95 ($39.95)
Sales of this book support The Perl Foundation! Get a printed copy>>>
28.1.10 Time and Date
The system's notion of time of day and calendar date is controlled in
widely different ways. Don't assume the timezone is stored in
and even if it is, don't assume that you can control the timezone through
that variable. Don't assume anything about the three-letter timezone
abbreviations (for example that MST would be the Mountain Standard Time,
it's been known to stand for Moscow Standard Time). If you need to
use timezones, express them in some unambiguous format like the
exact number of minutes offset from UTC, or the POSIX timezone
Don't assume that the epoch starts at 00:00:00, January 1, 1970,
because that is OS- and implementation-specific. It is better to
store a date in an unambiguous representation. The ISO 8601 standard
defines YYYY-MM-DD as the date format, or YYYY-MM-DDTHH-MM-SS
(that's a literal "T" separating the date from the time).
Please do use the ISO 8601 instead of making us to guess what
date 02/03/04 might be. ISO 8601 even sorts nicely as-is.
A text representation (like "1987-12-18") can be easily converted
into an OS-specific value using a module like Date::Parse.
An array of values, such as those returned by
localtime, can be
converted to an OS-specific representation using Time::Local.
When calculating specific times, such as for tests in time or date modules, it may be appropriate to calculate an offset for the epoch.
require Time::Local; my $offset = Time::Local::timegm(0, 0, 0, 1, 0, 70);
The value for
$offset in Unix will be
0, but in Mac OS Classic
will be some large number.
$offset can then be added to a Unix time
value to get what should be the proper value on any system.
|ISBN 9781906966027||Perl Language Reference Manual||See the print edition|