settimeofday()--Set System Clock
Syntax
#include <sys/time.h>
int settimeofday (struct timeval *tp,
struct timezone *tzp);
Service Program Name: QWCTZUTC
Default Public Authority: *USE
Threadsafe: Yes
The settimeofday() function sets the system clock to the Coordinated Universal Time (UTC) contained in the timeval structure pointed to by tp. The tzp parameter is not used.
Parameters
- tp
- (Input) A pointer to a timeval structure that contains the time in seconds
and microseconds since 1 January 1970, 00:00:00 UTC (epoch-1970).
- tzp
- This parameter is not used.
Authorities and Locks
- Special Authority
- *ALLOBJ
Return Value
| 0 | settimeofday() was successful. |
| -1 | settimeofday() was not successful. The errno variable is set to indicate the error. |
Error Conditions
If settimeofday() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
| [EACCES] | Permission denied.
An attempt was made to access an object in a way forbidden by its object access permissions. |
| [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. |
| [EPERM] | Operation not permitted.
You must have appropriate privileges or be the owner of the object or other resource to do the requested operation. |
| [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. |
Error Messages
None.
Related Information
- The <sys/time.h> file (see Header Files for UNIX®-Type Functions)
- adjtime()--Adjust System Clock
- gettimeofday()--Get Current UTC Time
Example
The following example sets the system clock.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
struct timeval now;
int rc;
now.tv_sec=866208142;
now.tv_usec=290944;
rc=settimeofday(&now, NULL);
if(rc==0) {
printf("settimeofday() successful.\n");
}
else {
printf("settimeofday() failed, "
"errno = %d\n",errno);
return -1;
}
return 0;
}
Example Output:
settimeofday() successful.
API introduced: V4R2