Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

tzfile(5)

getenv(3)

time(2)

chzone(8)

CTIME(3)  —  UNIX Programmer’s Manual

NAME

ctime, localtime, gmtime, asctime, tzset, tzsetwall, timezone − convert date and time to ASCII

SYNOPSIS

extern char ∗tzname[2];

void tzset()

void tzsetwall()

char ∗ctime(clock)
long ∗clock;

#include <sys/time.h>

char ∗asctime(tm)
struct tm ∗tm;

struct tm ∗localtime(clock)
long ∗clock;

struct tm ∗gmtime(clock)
long ∗clock;

char ∗timezone(zone, dst)

DESCRIPTION

Tzset uses the value of the environment variable TZ to set time conversion information used by localtime. If TZ does not appear in the environment, the best available approximation to local wall clock time is used by localtime. If TZ appears in the environment but its value is a null string, Greenwich Mean Time is used (without leap second correction); if TZ appears and begins with a slash, it is used as the absolute pathname of the tzfile(5)-format file from which to read the time conversion information; if TZ appears and begins with a character other than a slash, it’s used as a pathname relative to a system time conversion information directory. 

Tzsetwall sets things up so that localtime returns the best available approximation of local wall clock time. 

Ctime converts a long integer, pointed to by clock, representing the time in seconds since 00:00:00 GMT, January 1, 1970, 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. 

Localtime and gmtime return pointers to “tm” structures, described below.  Localtime corrects for the time zone and any time zone adjustments (such as Daylight Saving Time in the U.S.A.).  Before doing so, localtime calls tzset (if tzset has not been called in the current process).  After filling in the “tm” structure, localtime sets the tm_isdst’th element of tzname to a pointer to an ASCII string that’s the time zone abbreviation to be used with localtime’s return value.

Gmtime converts to Greenwich Mean Time (GMT). 

Asctime converts a time value contained in a “tm” structure to a 26-character string, as shown in the above example, and returns a pointer to the string. 

Declarations of all the functions and externals, and the “tm” structure, are in the <sys/time.h> header file.  The structure (of type) struct tm includes 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 DST in effect? ∗/

Tm_isdst is non-zero if a time zone adjustment such as Daylight Saving Time is in effect. 

Timezone returns the name of the time zone associated with its first argument, which is measured in minutes westward from Greenwich.  If the second argument is 0, the standard name is used, otherwise the Daylight Saving version.  If the required name does not appear in a table built into the routine, the difference from GMT is produced; e.g.  in Afghanistan timezone(-(60∗4+30), 0) is appropriate because it is 4:30 ahead of GMT and the string GMT+4:30 is produced. 

FILES

/etc/zoneinfotime zone information directory
/etc/zoneinfo/localtimelocal time zone file
/etc/zoneinfo/GMTGMT file (needed for leap seconds)

SEE ALSO

tzfile(5), getenv(3), time(2), chzone(8)

NOTE

The return values point to static data whose content is overwritten by each call. 

NEWS-OSRelease 3.3

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026