[TriLUG] changing Unix time to human time

Aaron S. Joyner aaron at joyner.ws
Mon Jun 21 11:04:06 EDT 2004


Dan wrote:

> My squid proxy logs its time stamps using what I think is the Unix 
> time stamp like:
>
> 1086628571.242
>
> any quick and dirty way to convert this to a human time stamp from the 
> command line?
>
>
perl -e '@tmp = localtime(1086628571.242); print "@tmp\n";'

This will give you something like this:

11 16 13 7 5 104 1 158 1

where the fields, in order, are
$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst

 From the perldoc page for localtime():

> All list elements are numeric, and come straight out of the C `struct 
> tm'.  $sec, $min, and $hour are the seconds, minutes, and hours of the 
> specified time.  $mday is the day of the month, and $mon is the month 
> itself, in the range C<0..11> with 0 indicating January and 11 
> indicating December.  $year is the number of years since 1900.  That 
> is, $year is C<123> in year 2023.  $wday is the day of the week, with 
> 0 indicating Sunday and 3 indicating Wednesday.  $yday is the day of 
> the year, in the range C<0..364> (or C<0..365> in leap years.)  $isdst 
> is true if the specified time occurs during daylight savings time, 
> false otherwise.

That's how I do it, personally.  There very-well may be a better way.  :)

Enjoy!

Aaron S. Joyner



More information about the TriLUG mailing list