Veritas-bu

[Veritas-bu] Re: Convert "English Time" back to "seconds past the epoch" (slig htly simpler)

2005-02-02 23:23:49
Subject: [Veritas-bu] Re: Convert "English Time" back to "seconds past the epoch" (slig htly simpler)
From: Mark.Hickey AT hds DOT com (Mark Hickey)
Date: Wed, 2 Feb 2005 20:23:49 -0800
Ed, 
   Here is something similar to what Steve Green sent, but is a bit simpler
and accepts a second argument specifying the timezone offset from the
current time zone.  This is handy when trying to understand a log sequence
from a datacenter on a different coast or what have you.

Mark

#!/usr/contrib/bin/perl

$nargs=@ARGV;
$correction = 0;
$x = localtime($ARGV[0]);
if ($nargs == 2)
{
    $offset = $ARGV[1];
    $correction = $offset * 3600;
}
$y = localtime($ARGV[0]+$correction);

print "$ARGV[0] converts to $x (localtime($ARGV[0]))\n";
print "$ARGV[0] with the correction is $y\n";

-----Original Message-----
From: veritas-bu-admin AT mailman.eng.auburn DOT edu
[mailto:veritas-bu-admin AT mailman.eng.auburn DOT edu] On Behalf Of
veritas-bu-request AT mailman.eng.auburn DOT edu
Sent: Wednesday, February 02, 2005 1:09 PM
To: veritas-bu AT mailman.eng.auburn DOT edu
Subject: Veritas-bu digest, Vol 1 #3790 - 7 msgs


Message: 3
From: "Green, Steven" <steven.green AT teldta DOT com>
To: "'veritas-bu AT mailman.eng.auburn DOT edu'"
         <veritas-bu AT mailman.eng.auburn DOT edu>
Date: Wed, 2 Feb 2005 08:58:29 -0600 
Subject: [Veritas-bu] Re: Convert "English Time" back to "seconds past the
epoch"

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C50937.A7ACD1EB
Content-Type: text/plain

To convert epoch (unix time) to standard time:

#!/usr/local/bin/perl
## Syntax: <scriptname> unix_time
use Time::Local;
$EPOCH = ($ARGV[0] > 0) ? $ARGV[0] : 0;
($sec, $min, $hr, $day, $mon, $yr, $wday) = localtime($EPOCH);
printf "unix time: $EPOCH ; std time: %02d/%02d/%04d %02d:%02d:%02d\n", 
        $mon+1,$day,$yr+1900,$hr,$min,$sec;

To convert standard time to epoch:

#!/usr/local/bin/perl
## Syntax: <scriptname> mm/dd/yy[yy] hh:mm:ss
use Time::Local;
($hr, $min, $sec) = split(/:/, $ARGV[1]);
($mon, $day, $yr) = split(/\//, $ARGV[0]);
$yr -= 100  if (length($yr) eq 4);
$yr += 1900 if (length($yr) le 1900);
$EPOCH = timelocal($sec, $min, $hr, $day, ($mon-1), $yr+100);
printf "unix time: $EPOCH ; std time: $ARGV[0] $ARGV[1]\n";


<Prev in Thread] Current Thread [Next in Thread>
  • [Veritas-bu] Re: Convert "English Time" back to "seconds past the epoch" (slig htly simpler), Mark Hickey <=