ftime()--Get Date and Time
Syntax
#include <sys/timeb.h> int ftime (struct timeb *tp);
Service Program Name: QWCTZUTC
Default Public Authority: *USE
Threadsafe: Yes
The ftime() function retrieves the current Coordinated Universal Time (UTC) and places it in timeb structure pointed to by tp.
Parameters
- tp
- (Output) A pointer to a timeb structure that contains the time in seconds
and milliseconds since 1 January 1970, 00:00:00 UTC (epoch-1970), the local time
zone (measured in minutes west of Greenwich), and a flag that, if nonzero, indicates
Daylight Saving Time is currently in effect.
Authorities and Locks
None
Return Value
| 0 | ftime() was
successful. |
| -1 | ftime() was not successful. The errno variable is set to indicate the error. |
Error Conditions
If ftime() 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. |
Error Messages
None.
Related Information
- The <sys/timeb.h> file (see Header Files for UNIX®-Type Functions)
- gettimeofday()--Get Current UTC Time
Example
The following example gets the current date and time.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#include <sys/timeb.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
struct timeb now;
int rc;
rc=ftime(&now);
if(rc==0) {
printf("ftime() successful.\n");
printf("time = %u.%03u, "
"timezone = %d, "
"dstflag = %d\n",
now.time, now.millitm,
now.timezone,
now.dstflag );
}
else {
printf("ftime() failed, errno = %d\n",
errno);
return -1;
}
return 0;
}
Example Output:
ftime() successful. time = 1019833362.226 timezone = 360, dstflag = 1
API introduced: V5R3