ctime(3C)
NAME
ctime(), ctime_r(), localtime(), localtime_r(), gmtime(), gmtime_r(), mktime(), difftime(), asctime(), asctime_r(), timezone(), daylight(), tzname(), tzset() − convert date and time to string
SYNOPSIS
#include <time.h>
char *asctime(const struct tm *timeptr);
int asctime_r(const struct tm *timeptr, char *buffer, int buflen);
char *ctime(const time_t *timer);
int ctime_r(const time_t *timer, char *buffer, int buflen);
double difftime(time_t time1, time_t time0);
struct tm *gmtime(const time_t *timer);
int gmtime_r(const time_t *timer, struct tm *result);
struct tm *localtime(const time_t *timer);
int localtime_r(const time_t *timer, struct tm *result);
time_t mktime(struct tm *timeptr);
extern long timezone;
extern int daylight;
extern char *tzname[2];
void tzset(void);
DESCRIPTION
asctime() Convert the broken-down time contained in the structure pointed to by timeptr and return a pointer to a 26-character string in the form:
Sun Sep 16 01:03:52 1973\n\0
All the fields have constant width.
asctime_r() is identical to asctime(), except that the result is returned in the supplied buffer. A buffer length of 26 is recommended.
ctime() Convert the calendar time pointed to by timer, representing the time in seconds since the Epoch, and return a pointer to the local time in the form of a string. Equivalent to:
asctime(localtime(timer))
ctime_r() is identical to ctime(), except that the result is returned in the supplied buffer. A buffer length of 26 is recommended.
gmtime() Convert directly to Coordinated Universal Time (UTC), the time standard used by the HP-UX operating system. gmtime() returns a pointer to the tm structure described below.
gmtime_r() is identical to gmtime(), except that gmtime_r() expects to be passed the address of a tm struct and will store the result at the supplied address.
localtime() Correct for the time zone and any summer time zone adjustments (such as Daylight Savings Time in the USA localtime() returns a pointer to the tm structure described below.
localtime_r() is identical to localtime(), except that localtime_r() expects to be passed the address of a tm struct and will store the result at the supplied address.
difftime() Return the difference in seconds between two calendar times: time1 − time0.
mktime() Convert the broken-down time (expressed as local time) in the structure pointed to by timeptr into a calendar time value with the same encoding as that of the values returned by time(2). The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values of the other components are not restricted to the ranges indicated below.
A positive or zero value for tm_isdst causes mktime() to initially presume that Daylight Saving Time respectively is or is not in effect for the specified time. A negative value for tm_isdst causes mktime() to attempt to determine whether Daylight Saving Time is in effect for the specified time.
Upon successful completion, all the components are set to represent the specified calendar time, but with their values forced to the ranges indicated below. The final value of tm_mday is not set until tm_mon and tm_year are determined. mktime() returns the specified calendar time encoded as a value of type time_t.
If the calendar time cannot be represented, the function returns the value (time_t)—1 and sets errno to ERANGE. Note the value (time_t)—1 also corresponds to the time 23:59:59 on Dec 31, 1969 (plus or minus time zone and Daylight Saving Time adjustments). Thus it is necessary to check both the return value and errno to reliably detect an error condition.
tzset() Sets the values of the external variables timezone, daylight, and tzname according to the contents of the TZ environment variable (independent of any time value). The functions localtime(), mktime(), ctime(), asctime(), and strftime() (see strftime(3C)) call tzset() and use the values returned in the external variables described below for their operations. tzset() can also be called directly by the user.
The <time.h> header file contains declarations of all relevant functions and externals. It also contains the tm structure, which includes the following members:
int tm_sec; /* seconds after the minute - [0,61] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours - [0,23] */
int tm_mday; /* day of month - [1,31] */
int tm_mon; /* month of year - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
The value of tm_isdst is positive if a summer time zone adjustment such as Daylight Savings Time is in effect, zero if not in effect, and negative if the information is not available.
The external variable timezone contains the difference, in seconds, between UTC and local standard time (for example, in the U.S. Eastern time zone (EST), timezone is 5∗60∗60). The external variable daylight is non-zero only if a summer time zone adjustment is specified in the TZ environment variable. The external variable tzname[2] contains the local standard and local summer time zone abbreviations as specified by the TZ environment variable.
EXTERNAL INFLUENCES
Locale
The LC_CTYPE category determines the interpretation of the bytes within format as single and/or multi-byte characters.
Environment Variables
The tzset() function uses the contents of TZ to set the values of the external variables timezone, daylight , and tzname. TZ also determines the time zone name substituted for the %Z and %z directives and the time zone adjustments performed by localtime(), mktime(), and ctime(). Two methods for specifying a time zone within TZ are described in environ(5).
International Code Set Support
Single- and multi-byte character code sets are supported.
RETURN VALUE
For asctime_r() and ctime_r(), if the buffer is of insufficient length, -1 is returned. For asctime_r(), ctime_r(), gmtime_r(), and localtime_r(), if the operation is successful, 0 is returned.
WARNINGS
The return values for asctime(), ctime(), gmtime(), and localtime() point to static data whose contents is overwritten by each call. Thus, these routines are unsafe in multi-thread applications. asctime_r(), ctime_r(), gmtime_r(), and localtime_r() are MT-Safe and should be used instead.
Users of asctime_r(), ctime_r(), gmtime_r(), and localtime_r() should also note that the prototypes of these functions will change in the next release for conformance with the new POSIX Threads standard.
The range of tm_sec([0,61]) extends to 61 to allow for the occasional one or two leap seconds. However, the “seconds since the Epoch” value returned by time(2) and passed as the timer argument does not include accumulated leap seconds. The tm structure generated by localtime() and gmtime() will never reflect any leap seconds. Upon successful completion, mktime() forces the value of the tm_sec component to the range [0,59].
ctime(), ctime_r(), asctime(), and asctime_r() are considered obsolescent and may be removed in a future release. Use of strftime(3C) is recommended instead.
AUTHOR
ctime() was developed by AT&T and HP.
SEE ALSO
time(2), getdate(3C), setlocale(3C), strftime(3C), tztab(4), environ(5), hpnls(5), lang(5), langinfo(5).
STANDARDS CONFORMANCE
ctime(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
asctime(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
daylight: AES, SVID2, SVID3, XPG2, XPG3, XPG4
difftime(): AES, SVID3, XPG4, ANSI C
gmtime(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
localtime(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
mktime(): AES, SVID3, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
timezone: AES, SVID3, XPG2, XPG3, XPG4
tzname: AES, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1
tzset(): AES, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1
Hewlett-Packard Company — HP-UX Release 10.20: July 1996