time will do just that for the current time. If you want to convert another time to epoch seconds check out Time::Local
ie
use Time::Local;
my $epoch_secs=timelocal( $sec, $min, $hrs, $dd, $mm-1, $yy);
vroom | Tim Vroom | vroom@cs.hope.edu
| [reply] [d/l] |
The Date::Calc
module will let you do date computations back to the year 1 C.E..
The Delta_Days function should be just what you need.
my $dd=Delta_Days(1,1,1,$cur_yr,$cur_mo,$cur_da);
If you're interested in how to do the calculation by hand
I highly recommend checking out
Calenderical Calculations by Derschowitz and
Reingold. Should be available at any bookstore w/ a
reasonably complete techincal section.
Looking at vrooms answer and mine reminds
me that you need
to be careful in how you define epoch.
In general terms eopch is the
start-date of your calendar.
So when does your calendar start ???
- Jan 1, 1970 (unix Epoch)
- Jan 1, 1900 (another epoch used in computers)
- Jan 1, 1 (Gregorian epoch)
- etc..
In my answer I had assumed the Gregorian epoch. If you want
your "time from epoch" in seconds and your epoch is 1/1/1970 then
the time() function returns that. | [reply] [d/l] |
The function/sub time() returns the sec. since the epoch.
perl -e 'print time(), "\n";'
For example:
$var = time();
$var2 = ((($var / 365) / 24) / 60);
print "The minutes since the epoch is: $var2 \n"; | [reply] |
I know the Mac uses Jan 01, 1904 and VMS uses
November 17, 1858 (!!) but what uses Jan 1, 1900?
| [reply] |
The unix localtime function returns
years as # of years since 1970 (even though
the dates are stored internally
as seconds since 1970). Giving
an apparent epoch of 1900 (even
though its really 1970).
Also, most databases represent
dates as YYYY-MM-DD, but
some don't allow dates before 1900.
1900 as an epoch is more common in application
programs than at the OS level.
| [reply] |
I understand all that, I was just wondering if anyone knew
of an *OS* that actually used Jan 1, 2000 as their epoch. You'd
think it would be more common. Then again, if unix really *did*
use 1900, we'd be in a lot of trouble. It would have been a lot
easier if they had just used a 64-bit number and started at
year "0". :)
| [reply] |
| [reply] |