Reversing Time
December 13, 1999
Only Superman can reverse time, unless you know of some other
way to fly around the earth and make it rotate
backwards around its axis. I thought not. Perl can't reverse
time either, but it can understand time that
is written in the reverse -- that is, the conversion of hours,
minutes, seconds, and so forth into epoch time,
rather than the other way around.
The standard Perl distribution also includes the
module
Time::Local. Using this module, you can calculate the
epoch time by supplying the seconds, minutes, hours, day of
month, month, and year for a given date.
use Time::Local;
$someday=timelocal(0,30,10,15,2,99);
print scalar localtime($someday);
Yields:
Mon Mar 15 10:30:00 1999
This is nice, but we haven't really solved our initial
problem: writing the time in epoch seconds isn't comfortable,
but neither is writing the time as broken down into seconds,
hours, minutes, day of month, and so on. To tell you
what we want -- what we really, really want -- is a way to
move between human friendly dates such as "April
25, 1985" and epoch seconds. On its lonesome, Perl is
not capable of this acrobatic feat out-of-the-box, so
we must turn to a Perl module.
Chopped Time
The Perl You Need to Know
Date::Manip Gymnastics
|