Epoch2Date
From My Admin Page
Convert Epoch number of days to readable
Ok, first here is one script that gives you both ways :
#!/bin/sh USER=$1 CURRENT_EPOCH=`grep $USER /etc/shadow | cut -d: -f3` # Print when PW last changed CHANGED=`perl -e "print scalar localtime($CURRENT_EPOCH * 24 *3600);"` MDY=`perl -e "use POSIX qw(strftime); print scalar strftime('%m/%d/%y', localtime($CURRENT_EPOCH * 24 *3600));"` # echo "$USER's password on $HOST expires in $EXPIRE days" echo "$USER - password Last changed $CHANGED ($MDY) ." echo
So, assuming $CURRENT_EPOCH is 14216 (i.e. from /etc/shadow) :
perl -e "print scalar localtime($CURRENT_EPOCH * 24 *3600);"
results in an output like :
Tue Dec 2 18:00:00 2008
So to format it into MM/DD/YY format, do :
perl -e "use POSIX qw(strftime); print scalar strftime('%m/%d/%y', localtime($CURRENT_EPOCH * 24 *3600));
the output will be :
12/02/08
Use %Y instead of %y if you want full year displayed [2008 instead of 08].