Operating System - HP-UX
1753862 Members
7491 Online
108809 Solutions
New Discussion юеВ

Re: Converting UNIX epoch time to a date formatted %y%m%d%H%M%S

 
SOLVED
Go to solution
Danny Fang
Frequent Advisor

Converting UNIX epoch time to a date formatted %y%m%d%H%M%S

Hi,

I'm attempting to convert a UNIX epoch time obtained with the command shown below to a date having the format of %y%m%d%H%M%S:
sprnorda@aix% truss date 2>&1 | awk '/time/ {print $NF}'
1158845395

I'm not sure how I could pass the value "1158845395" to the 'date' utility.

I do have a Perl script which does that. However, i'd want to know how it should be done using any UNIX utilities or scripts.

Could anyone help me out?

Thanks
Danny
3 REPLIES 3
Peter Godron
Honored Contributor

Re: Converting UNIX epoch time to a date formatted %y%m%d%H%M%S

Danny,
from another site:
$ timer=1158845395
$ echo "0d$timer=Y" | adb | tr -d '\011'
2006 Sep 21 14:29:55
James R. Ferguson
Acclaimed Contributor

Re: Converting UNIX epoch time to a date formatted %y%m%d%H%M%S

Hi Danny:

# perl -MPOSIX=strftime -e 'print strftime("%m%d%H%M%Y\n",localtime($ARGV[0]))' 1158845395

...returns:

092109292006

Regards!

...JRF...

James R. Ferguson
Acclaimed Contributor
Solution

Re: Converting UNIX epoch time to a date formatted %y%m%d%H%M%S

Hi (again):

Oh, you wanted :%y%m%d%H%M%S", so:

# perl -MPOSIX=strftime -e 'print strftime("%y%m%d%H%M%S\n",localtime($ARGV[0]))' 1158845395

You can use any standard format that you want. Follow the directives in the man pages for 'strftime(3C)' or for 'date(1)'.

Regards!

...JRF...