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(3V)

CTIME(3)  —  C LIBRARY FUNCTIONS

NAME

ctime, localtime, gmtime, asctime, timezone, dysize − 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;

char ∗timezone(zone, dst)

int dysize(y)
int y;

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 broken-down time.  localtime corrects for the time zone and possible daylight savings time; gmtime converts directly to GMT, which is the time UNIX uses.  asctime converts a 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. 

When local time is called for, the program consults the system to determine the time zone and whether the U.S.A., Canadian, Australian, Eastern European, Middle European, or Western European daylight saving time adjustment is appropriate.  The program knows about various peculiarities in time conversion over the past 10-20 years. 

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 Savings Time 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. 

dysize returns the number of days in the argument year, either 365 or 366. 

SEE ALSO

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

BUGS

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

Sun Release 3.5  —  Last change: 15 April 1986

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