#include <sys/time.h> int gettimeofday (struct timeval *tp, struct timezone *tzp);
The gettimeofday() function retrieves the current Coordinated Universal Time (UTC) and places it in the timeval structure pointed to by tp. If tzp is not NULL, the time zone information is returned in the time zone structure pointed to by tzp.
None
0 | gettimeofday() was
successful. |
-1 | gettimeofday() was not successful. The errno variable is set to indicate the error. |
If gettimeofday() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
[EINVAL] | An invalid parameter was found.
A parameter passed to this function is not valid. |
[EFAULT] | The address used for an argument is not correct.
In attempting to use an argument in a call, the system detected an address that is not valid. While attempting to access a parameter passed to this function, the system detected an address that is not valid. |
[EUNKNOWN] | Unknown system state.
The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation. |
None.
See Code disclaimer information for information pertaining to code examples.
The following example gets the current UTC time:
#include <sys/time.h> #include <stdio.h> #include <errno.h> int main(int argc, char *argv[]) { struct timeval now; int rc; rc=gettimeofday(&now, NULL); if(rc==0) { printf("gettimeofday() successful.\n"); printf("time = %u.%06u\n", now.tv_sec, now.tv_usec); } else { printf("gettimeofday() failed, errno = %d\n", errno); return -1; } return 0; }Example Output:
gettimeofday() successful. time = 866208142.290944
Top | UNIX-Type APIs | APIs by category |