how to convert epoch time to readible format?

Hi,
I would like to convert epoch time from the logs to readible fromat.
How do I do it within shell?

Thanks!

what OS are you on?

what's the command to do it?

ok.
Here it is:
System Configuration: Sun Microsystems sun4u
Memory size: 512 Megabytes

Aim this module at your perl ie., #!/path/to/your/perl

#!/usr/bin/perl
# date from time_t seconds since the start of epoch  then.pl
$then = localtime($ARGV[0]); 
print("$then\n");

usage:

logdate=`then.pl <time since start of epoch>`
echo "$logdate"
#!/bin/ksh

# here's my current EPOCH time
currentEpoch=$(/usr/bin/truss /usr/bin/date 2>&1 | /usr/bin/awk '/^time/ {print $NF}')

# here we convert EPOCH back to human readable format
back2Human=$(echo "0t${currentEpoch}=Y" | /usr/bin/adb)

echo "date->[$(date)] currentEpoch->[${currentEpoch}] back2Human->[${back2Human}]"

cin2000, "uname -a" will tell you the os.

vger99, I like that procedure to to get the internal time. I'll never use it, mind you. But I like it anyway. :slight_smile: Another way which requires root (or at least non-standard) permission: "echo time/D | adb -k" I used to like these adb tricks but since 64 bit kernels started to arrive they are not as much fun. On a 64 bit kernel, you may need: "echo time+4/D | adb -k"

Between the 32/64 bit confusion and the user permission problems, I have started using perl for this stuff: perl -e 'print time, "\n"'.

vgersh99,
Is there anyway to modify your code to pass date as variable(120905)?
the format will be like mmddyy.
What does /^time/ mean here?

currentEpoch=$(/usr/bin/truss /usr/bin/date 2>&1 | /usr/bin/awk '/^time/ {print $NF}')

This is not 'epoch time' format - totally different question!

This means 'get the line starting with the string 'time'

Agreed - perl is somewhat more 'generic', but in some cases [at least for me] I don't have the luxury on relying on 'perl' being installed on the 'target' system.

Hi,
Thanks a lot for the help on epoch convertion.
I thought I know how to convert regular date format to epoch time...
But I don't...
I need to convert something like 093005(mmddyy) format to epoch time to put back into the log file, not just current system date time.

Is there way to do it?

Your help is greatly appreciated!!

I found the solution by using perl:

#!/usr/bin/perl
# date from time_t seconds since the start of epoch then.pl
use Time::Local;
$epoch = timelocal( 0,0,0,19,11,2005 );
print("$epoch\n");