1840640 Members
3505 Online
110166 Solutions
New Discussion

getting UNIX epoch time

 
Danny Fang
Frequent Advisor

getting UNIX epoch time

Hi,

I'm attempting to obtain the UNIX epoch time(since 1970) on a HPUX machine. I've tried with the 'truss' utility i.e.
/usr/bin/truss /usr/bin/date 2>&1|/usr/bin/awk '/time/ {print $NF}'
1159448101

On a GNU platform, I could do:
mz[t1]$ date '+%s'
1159448106

Unfortunately, I do have the GNU date/utilities installed on my HPUX-11 machine.

May I know what is the more effecient or simple way to obtain the UNIX epoch time, instead of using the truss?

Thanks
Danny
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: getting UNIX epoch time

perl -e 'print time()'
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: getting UNIX epoch time

Hi Danny:

use Perl;

# perl -le 'print time'

# perl -le 'print scalar localtime(time)'

# perl -le 'print scalar localtime(86400)'

Regards!

...JRF...
Thomas Elsäßer
New Member

Re: getting UNIX epoch time

echo "0d995462197=Y" | adb
2001 Jul 18 15:16:37
Danny Fang
Frequent Advisor

Re: getting UNIX epoch time

Hi Thomas,

With regards to your solution posted below,
echo "0d995462197=Y" | adb
2001 Jul 18 15:16:37

could you explain what does the "0d995462197=Y" value mean when passed to the debugger?

Thanks
Danny
James R. Ferguson
Acclaimed Contributor

Re: getting UNIX epoch time

Hi Danny:

Passing "0d995462197=Y" to the debugger ('adb') says to take the *decimal* (0d) number (995462197) and convert it to a time_t object. This is documented in the 'adb' manpages:

http://www.docs.hp.com/en/B2355-60105/adb.1.html

Regards!

...JRF...