Operating System - HP-UX
1849583 Members
6792 Online
104044 Solutions
New Discussion

Micro/milliseconds since epoch

 
SOLVED
Go to solution
Jakes Louw
Trusted Contributor

Micro/milliseconds since epoch

Hi all

I'm looking for a utility or script that will return milliseconds or preferably microseconds from epoch until present, or until a specific date.

On mainframes, we had "dateandtimeinmicroseconds", but I know nothing like that exists on standard HP-UX.

Trying is the first step to failure - Homer Simpson
2 REPLIES 2
Mark Grant
Honored Contributor

Re: Micro/milliseconds since epoch

You don't have a utility as such but there is the 'C' gettimeofday() function.

Here is a bare bones example of how you might use it. Beware, I haven't actually tried to compile this :)

#include

main(){

struct timeval t;
struct timezone tz;

gettimeofday(&t,&tz);
printf("Time in seconds is %ld and %ld micro-seconds\n",t.tv_sec,t.tv_usec);
}


Never preceed any demonstration with anything more predictive than "watch this"
Ross Barton
Occasional Advisor
Solution

Re: Micro/milliseconds since epoch

See also the thread http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=602110

#include

struct timeval now;
struct timezone timezone;

gettimeofday(&now,&timezone);

/* now.tv_sec is seconds since EPOCH
(1/1/1970 00:00:00) */

/* now.tv_usec is microseconds in the current second */

do a man on "gettimeofday" and have a look in the time.h include file for more info and details of the structures.
Note: Microseconds are not always accurate to the microsecond - there is some small error involved in the CPU calculating this. However, it would be insignificant in the calculation of milliseconds from microseconds. This error can be significant in calculation of timestamps for things like auditing software or flight simulations etc.

Enjoy
Rossco
Everything should be made as simple as possible, but not simpler. Albert Einstein.