Name

gettimeofday - gets time of day

Library

libc.lib

Synopsis

  #include <sys/time.h>
  int gettimeofday (struct timeval *tp, struct timezone *tzp);

Return values

The gettimeofday function returns 0 for success, or -1 for failure.

Detailed description

The system’s notion of the current Greenwich time and the current time zone is obtained with the gettimeofday system call, and set with the settimeofday system call. The time is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970. The resolution of the system clock is hardware dependent, and the time may be updated continuously or in "ticks." If tp or tzp is NULL, the associated time information will not be returned or set.

The structures pointed to by tp and tzp are defined in

  #include <sys/time.h>as:

struct timeval {
        long    tv_sec;         /* seconds since Jan. 1, 1970 */
        long    tv_usec;        /* and microseconds */
};
struct timezone {
        int     tz_minuteswest; /* minutes west of Greenwich */
        int     tz_dsttime;     /* type of dst correction */
};

                     

The timezone structure indicates the local time zone (measured in minutes of time westward from Greenwich), and a flag that, if nonzero, indicates that Daylight Saving time applies locally during the appropriate part of the year.


Examples

#include <stdio.h>
#include <sys/time.h>
 
int main()
{
  struct timeval *tv;
  struct timezone *tz;
  int i = gettimeofday(tv, tz);
      
  printf("tv: %d, %d\n", tv->tv_sec, tv->tv_usec);
  printf("tz: %d, %d\n", tz->tz_minuteswest, tz->tz_dsttime);
  return 0;
}

         

Output

tv: 1474660693, -326937770
tz: 7804688, 3

         

See also

adjtime, clock_gettime, ctime

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top