Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

gettimeofday(2)

time(3C)

getenv(3)

environ(5V)

ctime(3)

CTIME(3V)  —  UNKNOWN SECTION OF THE MANUAL

NAME

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

SYNOPSIS

char ∗ctime(clock)
long ∗clock;

#include <time.h>

struct tm ∗localtime(clock)
long ∗clock;

struct tm ∗gmtime(clock)
long ∗clock;

char ∗asctime(tm)
struct tm ∗tm;

extern long timezone;

extern int daylight;

extern char ∗tzname[2];

void tzset ( )

DESCRIPTION

ctime converts to ASCII a long integer, pointed to by clock, that represents the time in seconds since Jan. 1, 1970, 00:00, Greenwich Mean Time.  It returns a pointer to a 26-character string of the form:

Sun Sep 16 01:03:52 1973\n\0

Each field has a constant width.  localtime and gmtime return pointers to structures containing the time broken down.  localtime corrects for the time zone and possible daylight savings time; gmtime converts directly to GMT, which is the time UNIX uses.  asctime converts the broken-down time to ASCII and returns a pointer to a 26-character string. 

Declarations of all the functions and externals, and the “tm” structure, are in the <time.h> header file.  The structure declaration is:

struct tm {
        int tm_sec;/∗ seconds (0 - 59) ∗/
        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;
};

tm_isdst is non-zero if Daylight Savings Time is in effect. 

The external long variable timezone contains the difference, in seconds, between GMT and local standard time (in PST, timezone is 8∗60∗60); the external variable daylight is non-zero if and only if Daylight Savings Time conversion should be applied.  Its value indicates the type of conversion to apply; it is normally the value returned by gettimeofday (2) in the tz_dsttime field of the timezone structure.  The program knows about various peculiarities in time conversion over the past 10-20 years. 

The external variable tzname is an array of two pointers which contains the names of the current time zone.  The first pointer points to a character string which is the name of the current time zone when Daylight Savings Time is not in effect; the second one, if Daylight Savings Time conversion should be applied, points to a character string which is the name of the current time zone when Daylight Savings Time is in effect. 

If an environment variable named TZ is present, asctime uses the contents of the variable to override the time zone and conversion rule type supplied by the system.  The value of TZ must be a three-letter time zone name, followed by a signed number representing the difference between local time and Greenwich Mean Time in hours, followed by an optional three-letter name for a daylight time zone.  For example, the setting for California would be PST8PDT.  The effects of setting TZ are thus to change the values of the external variables timezone, daylight, and tzname. The function tzset sets these external variables from TZ or, if TZ is not present in the environment, the values supplied by the system.  tzset is called by asctime and may also be called explicitly by the user. 

SEE ALSO

gettimeofday(2), time(3C), getenv(3), environ(5V), ctime(3)

BUGS

The return values point to static data, whose contents are overwritten by each call. 

Sun Release 3.2  —  Last change: 15 April 1986

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