time(),time64() — Determine current UTC time
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
Format
#include <time.h>
time_t time(time_t *timeptr);
#define _LARGE_TIME_API
#include <time.h>
time64_t time64(time64_t *timer);
General description
Determines the current UTC time.
Returned value
The time() function returns the value of time in seconds since the Epoch.
Returns the current UTC time. The returned value is also stored in the location given by timeptr. If timeptr is NULL, the returned value is not stored. If the calendar time is not available, the value (time_t)-1 is returned.
time() returns the current value of the time-of-day (TOD) clock value obtained with the STCK instruction, rounded off to the nearest second, and normalized to the POSIX Epoch, January 1, 1970. The TOD clock value does not account for leap seconds. If you need more accuracy, use the STCK instruction or the TIME macro which does account for leap seconds using whatever value the system operator has entered for number of leap seconds in the CVT field. For more information about the STCK instruction, refer to z/Architecture Principles of Operation.
A returned value of 0 indicates the epoch, which was at the Coordinated Universal Time (UTC) of 00:00:00 on January 1, 1970.
The function time64() will behave exactly like time() except it will support calendar times beyond 03:14:07 UTC on January 19, 2038.
Example
/* CELEBT11
This example gets the time and assigns it to ltime, then uses
the &ctime. function to convert the number of seconds to the
current date and time.
Finally, it prints a message giving the current time.
*/
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t ltime;
time(<ime);
printf("The time is %s\n", ctime(<ime));
}
The time is Fri Jun 16 11:01:41 2006
Related information
- time.h
- asctime(), asctime64() — Convert time to character string
- asctime_r(), asctime64_r() — Convert date and time to a character string
- clock() — Determine processor time
- ctime(), ctime64() — Convert time to character string
- ctime_r(), ctime64_r() — Convert time value to date and time character string
- gmtime(), gmtime64() — Convert time to broken-down UTC time
- gmtime_r(), gmtime64_r() — Convert a time value to broken-down UTC time
- localdtconv() — Date and time formatting convention inquiry
- localtime(), localtime64() — Convert time and correct for local time
- localtime_r(), localtime64_r() — Convert time value to broken-down local time
- mktime(), mktime64() — Convert local time
- strftime() — Convert to formatted time
- tzset() — Set the time zone