time(),time64() — Determine current UTC time

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3
Language Environment

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
⁄* 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(&ltime);                                                                
   printf("The time is %s\n", ctime(&ltime));                                   
}                                                                               
Output
The time is Fri Jun 16 11:01:41 2001

Related information