Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > G

gettimeofday(2)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

gettimeofday — get the date and time

SYNOPSIS

#include <sys/time.h>

int gettimeofday(struct timeval *tp, void *tzp);

DESCRIPTION

The gettimeofday() function obtains the current time, expressed as seconds and microseconds since Epoch, and stores it in the timeval structure pointed to by tp.

The resolution of the system clock is one microsecond.

PARAMETERS

Programs should use this time zone information only in the absence of the TZ environment variable.

tp

A pointer to a timeval structure in which the current time is returned.

The timeval structure includes the following members:

time_t tv_sec /* Seconds. */ long tv_usec /* Microseconds. */

tzp

If this parameter is not a null pointer, it is interpreted as a pointer to a timezone structure under HP-UX. The timezone structure has the following fields:

tz_minuteswest

The number of minutes that the local time zone is west of Coordinated Universal Time (UTC) or Epoch.

tz_dsttime

A flag that, if nonzero, indicates that Daylight Savings Time (DST) applies locally during the appropriate part of the year.

RETURN VALUE

gettimeofday() returns the following values under HP-UX:

0

Successful completion.

-1

Failure. errno is set to indicate the error.

ERRORS

If gettimeofday() fails, errno is set to the following value under HP-UX:

[EFAULT]

An argument address referenced invalid memory.

EXAMPLES

The following HP-UX 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;

WARNINGS

Relying on a granularity of one microsecond may result in code that is not portable to other platforms.

AUTHOR

gettimeofday() was developed by the University of California, Berkeley, and HP.

SEE ALSO

date(1), ftime(2), settimeofda(2), stime(2), time(2), ctime(3C).

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.