Operating System - Linux
1752579 Members
4673 Online
108788 Solutions
New Discussion

Re: HP-UX shell or OE access to epoch secs

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

Re: HP-UX shell or OE access to epoch secs

>Sandman!:  printf("%ld\n", time(ptloc));

There is no need to pass a parm to time(2). This also makes the kernel sweat because it has to validate it. Just use time(NULL).

Ralph Grothe
Honored Contributor

Re: HP-UX shell or OE access to epoch secs

Hello Guys,

many thanks for all the efforts you took further elaborating on my somewhat idle query.


Madness, thy name is system administration

Re: HP-UX shell or OE access to epoch secs

Not actually Laurie, but wanted to share a similar solution to Clays but hopefully easier for them young folk to support once I am gone (first version used bc(1) just because I wanted to try :-):

function secsFromEpoch {

# Good until 2100

typeset -i year=0
typeset -i jDay=0
typeset -i hour=0
typeset -i min=0
typeset -i sec=0
typeset -i totalDays=0
typeset -i totalHours=0
typeset -i totalMinutes=0
typeset -i totalSeconds=0

date -u +"%Y %j %H %M %S" | read year jDay hour min sec

(( totalDays = ($year - 1970)*365 + ($year - 1968)/4 + $jDay - 1 ))
(( totalHours = $totalDays*24 + $hour ))
(( totalMinutes = $totalHours*60 + $min ))
(( totalSeconds = $totalMinutes*60 + $sec ))

echo $totalSeconds