This is a quick way to convert from epoch time to local time.

This can be used for example if running lsuser in AIX and converting the time_last_login field.

If lsuser gets back “time_last_login=1298298259“, then

perl -le 'print scalar localtime 1298298259'
Mon Feb 21 14:24:19 2011

Viola – thankyou google and Nicholas.

You can also do the following in bash for example if you want to check the change time on a file…

file=/tmp/file
ctime=`stat $file | grep Change`
filetime=${ctime#Change\:*}
epochtime=`date -d "$filetime" +%s`      # Convert from a datestamp to epoch secs
now=`date +%s`                           # Get current date/time in epoch secs
(( diffepoch = now - epochtime ))
if [[ $diffepoch -gt 60 ]];then
  echo "$file is newer than 2 mins."
else
  echo "$file is older than 2 mins."
fi