|
|
HP-UX Reference Volume 3 of 5 > ggettimeofday(2) |
|
NAMEgettimeofday — get the date and time DESCRIPTIONThe gettimeofday() function obtains the current time, expressed as seconds and microseconds since 00:00 Coordinated Universal Time (UTC), January 1, 1970, and stores it in the timeval structure pointed to by tp. The resolution of the system clock is unspecified. If tzp is not a null pointer, the behaviour is unspecified. DESCRIPTIONThe structures pointed to by tp and tzp are defined in <time.h> as: struct timeval { unsigned long tv_sec; /* seconds since Jan. 1, 1970 */ long tv_usec; /* and microseconds */ }; struct timezone { int tz_minuteswest; /* of UTC */ int tz_dsttime; /* type of DST correction to apply */ }; The timezone structure indicates the local time zone (measured in minutes of time westward from UTC), and a flag that, if nonzero, indicates that Daylight Savings Time applies locally during the appropriate part of the year. Programs should use this time zone information only in the absence of the TZ environment variable. RETURN VALUEgettimeofday() return the following values:
ERRORSgettimeofday() fails, errno is set to the following value.
EXAMPLESThe following example calls gettimeofday() twice. It then computes the lapsed time between the calls in seconds and microseconds and stores the result in a timeval structure: struct timeval first, second, lapsed; struct timezone tzp; gettimeofday (&first, &tzp); /* lapsed time */ gettimeofday (&second, &tzp); if (first.tv_usec > second.tv_usec) { second.tv_usec += 1000000; second.tv_sec--; } lapsed.tv_usec = second.tv_usec - first.tv_usec; lapsed.tv_sec = second.tv_sec - first.tv_sec; |
|