asctime_r3
Transform binary date and time values
Part of asctime(3).
Usage
extern char
*tzname
[2]
;
char *
char *
char *
char *
double
struct tm
*
struct tm
*
struct tm
*
struct tm
*
time_t
struct tm
*
struct tm
*
time_t
Library
Standard C Library (libc, -lc)
Overview
The ctime(), gmtime(), localtime(), and offtime() functions all take as argument a pointer to a time value representing the time in seconds since the Epoch (00:00:00 UTC on January 1, 1970; see time(3)).
The localtime() function converts the time value pointed to by clock, and returns a pointer to a struct tm (described below) which contains the broken-out time information for the value after adjusting for the current time zone (see tzset(3)). When the specified time translates to a year that will not fit in an int, localtime() returns NULL. The localtime() function uses tzset(3) to initialize time conversion information if tzset(3) has not already been called by the process.
After filling in the struct tm, localtime() sets the tm_isdst'th element of tzname to a pointer to an ASCII string that is the time zone abbreviation to be used with localtime(Ns, 's) return value.
The gmtime() function similarly converts the time value, but without any time zone adjustment, and returns a pointer to a struct tm.
The offtime() function similarly converts the time value with a time zone adjustment corresponding to the provided offset, which is expressed in seconds, with positive values indicating a time zone ahead of UTC (east of the Prime Meridian). It does not call tzset(3) or modify tzname.
The ctime() function adjusts the time value for the current time zone in the same manner as localtime(), and returns a pointer to a 26-character string of the form:
Thu Nov 24 18:22:48 1986\n\0
All the fields have constant width.
The asctime() function converts the broken down time in the struct tm pointed to by tm to the form shown in the example above.
The ctime_r() and asctime_r() functions provide the same functionality as ctime() and asctime() except the caller must provide the output buffer buf, which must be at least 26 characters long, to store the result in. The localtime_r(), gmtime_r(), and offtime_r() functions provide the same functionality as localtime(), gmtime(), and offtime() respectively, except the caller must provide the output buffer result.
The functions mktime() and timegm() convert the broken-down time in the struct tm pointed to by tm into a time value with the same encoding as that of the values returned by the time(3) function (that is, seconds from the Epoch, UTC). The mktime() function interprets the input structure according to the current timezone setting (see tzset(3)) while the timegm() function interprets the input structure as representing Universal Coordinated Time (UTC).
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 their normal ranges, and will be normalized if needed. For example, October 40 is changed into November 9, a tm_hour of -1 means 1 hour before midnight, tm_mday of 0 means the day preceding the current month, and tm_mon of -2 means 2 months before January of tm_year. (A positive or zero value for tm_isdst causes mktime() to presume initially that summer time (for example, Daylight Saving Time) is or is not in effect for the specified time, respectively. A negative value for tm_isdst causes the mktime() function to attempt to guess whether summer time is in effect for the specified time. The tm_isdst and tm_gmtoff members are forced to zero by timegm().)
On successful completion, the values of the tm_wday and tm_yday components of the structure are set appropriately, and the other components are set to represent the specified calendar time, but with their values forced to their normal ranges; the final value of tm_mday is not set until tm_mon and tm_year are determined. The mktime() function returns the specified calendar time; if the calendar time cannot be represented, it returns -1 and sets errno(3) to an appropriate value.
Note that -1 is a valid result (representing one second before midnight UTC on the evening of 31 December 1969), so this cannot be relied upon to indicate success or failure; instead, tm_wday and / or tm_yday should be set to an out-of-bounds value (e.g. -1) prior to calling mktime() or timegm() and checked after the call.
The difftime() function returns the difference in seconds between two time values, time1 - time0.
External declarations as well as the definition of struct tm are in the ⟨time.h⟩ header. The tm structure includes at least the following fields:
int tm_sec; /* seconds (0 - 60) */ int tm_min; /* minutes (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; /* year - 1900 */ int tm_wday; /* day of week (Sunday = 0) */ int tm_yday; /* day of year (0 - 365) */ int tm_isdst; /* is summer time in effect? */ char *tm_zone; /* abbreviation of timezone name */ long tm_gmtoff; /* offset from UTC in seconds */
The tm_isdst field is non-zero if summer time is in effect.
The tm_gmtoff field is the offset in seconds of the time represented from UTC, with positive values indicating a time zone ahead of UTC (east of the Prime Meridian).
History
- FreeBSD 16.0-CURRENT (2026-10-27) to FreeBSD 15.1-RELEASE: the text shown here
- FreeBSD 15.0-RELEASE
- FreeBSD 14.5-RELEASE
- FreeBSD 14.4-RELEASE to FreeBSD 14.1-RELEASE
- FreeBSD 14.0-RELEASE
- FreeBSD 13.5-RELEASE to FreeBSD 13.4-RELEASE
- FreeBSD 13.3-RELEASE
- FreeBSD 13.2-RELEASE
- FreeBSD 13.1-RELEASE to FreeBSD 13.0-RELEASE
- FreeBSD 12.4-RELEASE
- FreeBSD 12.3-RELEASE
- FreeBSD 12.2-RELEASE
- FreeBSD 12.1-RELEASE
- FreeBSD 12.0-RELEASE
- FreeBSD 11.4-RELEASE
- FreeBSD 11.3-RELEASE
- FreeBSD 11.2-RELEASE
- FreeBSD 11.1-RELEASE
- FreeBSD 11.0-RELEASE
- FreeBSD 10.4-RELEASE
- FreeBSD 10.3-RELEASE
- FreeBSD 10.2-RELEASE
- FreeBSD 10.1-RELEASE
- FreeBSD 10.0-RELEASE
- FreeBSD 9.3-RELEASE
- FreeBSD 9.2-RELEASE
- FreeBSD 9.1-RELEASE
- FreeBSD 9.0-RELEASE
- FreeBSD 8.4-RELEASE
- FreeBSD 8.3-RELEASE
- FreeBSD 8.2-RELEASE
- FreeBSD 8.1-RELEASE
- FreeBSD 8.0-RELEASE
- FreeBSD 7.4-RELEASE
- FreeBSD 7.3-RELEASE
- FreeBSD 7.2-RELEASE
- FreeBSD 7.1-RELEASE
- FreeBSD 7.0-RELEASE
- FreeBSD 6.4-RELEASE
- FreeBSD 6.3-RELEASE to FreeBSD 6.0-RELEASE
- FreeBSD 5.5-RELEASE to FreeBSD 5.3-RELEASE
- FreeBSD 5.2.1-RELEASE to FreeBSD 5.2-RELEASE
- FreeBSD 5.1-RELEASE
- FreeBSD 5.0-RELEASE
- FreeBSD 4.11-RELEASE to FreeBSD 4.9-RELEASE