[rescue] Help w/ computer time??

rescue at sunhelp.org rescue at sunhelp.org
Wed Apr 24 13:49:08 CDT 2002


> Since I really suck w/ perl I was wondering if one of you 
> might be able to help me quickly...  I have a file full of
> unix dates (epoch) listed one on a line.  I need to get
> these converted to localtime.  Is there a quick and dirty for
> this somewhere that I just can't find?

Here's something quick to get you started.  This is based
on calling the time() function (in about the third line
below) and using it to get the current clock time.  If
you turned most of what's below into a function, and
passed it the time_since_epoch as a parameter, it would
gladly convert it into something useful using the
localtime() feature.

The snippet below was designed to output both an
ISO-standard date string (2002-04-23) and a timestamp
(in a format determined by kernel-level auditfiles
on a particularly annoying OS...).  I probably stole
some of the code from the O'Reilly Perl books--the
script was dated 1999.

Hope this helps--
  --Rip

=-=-= Begin crappy excerpt from crappy script =-=-=

require 5;
require 'ctime.pl';

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;         ## Correct for zero-based data
foreach $i ($mon, $mday, $min, $hour) {
        if (length($i) < 2) {
                ### Add leading zero for display/sorting purposes
                $i = "0" . $i;
        }
}
$fullyear = $year+1900;  ## Year *is* Y2K compliant, but the return value
                         ## is (actual year - 1900)...sad but true.
$datestring = $fullyear . "-" . $mon . "-" . $mday;
$timestamp = "$year$mon$mday$hour$min";

=-=-= End crappy excerpt from crappy script =-=-=


> -----Original Message-----
> From: Linc Fessenden [mailto:linc at thelinuxlink.net]
> Sent: Wednesday, 24 April, 2002 14:33
> To: rescue at sunhelp.org
> Subject: [rescue] Help w/ computer time??
> 
> 

> 
> -Linc Fessenden
> 
> In the Beginning there was nothing, which exploded - Yeah right...
> _______________________________________________
> rescue list - http://www.sunhelp.org/mailman/listinfo/rescue



More information about the rescue mailing list