Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX Epoch Time to 'Human readable time'

Status
Not open for further replies.

DimSoiVer

Programmer
Jan 9, 2002
2
US
Hello,

I try to write a script to read some log files and I want to read some time fields. How do you convert UNIX Epoch Time to 'Human readable time'? I'm working on a IBM-AIX machine and I didn't find anything on it.

Thanks


Dimitri from Geneva
 
so, time as it returns from time in perl?

i have one, but something tells me it is not what you're for.. anyway, here:

sub formattime{
#arg - time
#mode: 0 - gmt, 1 - local
#length: 0 - truncated, 1 - full
my($arg,$mode,$length)=@_;

@DaysEn=("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
@MonthsEn=("January","February","March","April","May","June","July","August","September","October","November","December");

my(@timear)=($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=($mode ? localtime($arg) : gmtime($arg));

my(%Timeobj);

$Timeobj{sec}=sprintf("%02d",$timear[0]);
$Timeobj{min}=sprintf("%02d",$timear[1]);
$Timeobj{hour}=sprintf("%02d",$timear[2]);
$Timeobj{mday}=$timear[3];
$Timeobj{month}=($length ? $MonthsEn[$timear[4]] : substr($MonthsEn[$timear[4]],0,3) ;
$Timeobj{wday}=($length ? $DaysEn[$timear[6]] : substr($DaysEn[$timear[6]],0,3);
$Timeobj{year}=$timear[5]+1900;

my($del)=":";
#suf
if ($lang){
$suf="-å";
}else{
@suffEn=('th','st','nd','rd');
$lastdig=substr($mday,-1);
my($flag)=((($mday < 11) ||($mday > 20)) && $lastdig < 4);
$suf=($flag ? $suffEn[$lastdig] : &quot;th&quot; );
}

#for cookies:
#expires=$dayOfWeek, $mday-$monthName-$year $hour:$min:$sec GMT
#=> mode=0, lang=0, length=0
#=> &formattime(time,0,0);

my($timestring)=(&quot;&quot;);
$gmt=&quot; GMT&quot;;
$tfull=&quot;$Timeobj{wday}, $Timeobj{mday}$suf $Timeobj{month}, $Timeobj{year} $Timeobj{hour}$del$Timeobj{min}$del$Timeobj{sec}&quot;;
$ttrunc=&quot;$Timeobj{wday}, $Timeobj{mday}-$Timeobj{month}-$Timeobj{year} $Timeobj{hour}$del$Timeobj{min}$del$Timeobj{sec}&quot;;


$timestring=($length ? $tfull : $ttrunc );
$timestring.=$gmt if (!$mode);

return $timestring;
}
Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top