SUMMARY ctime2l ctime2tm date2l

#include <time.h>
#include <tools.h>

long ctime2l(p)
char * p;

struct tm *ctime2tm(p)
char *p;

long date2l(year, month, day, hour, min, sec)
int year, month, day, hour, min, sec;


DESCRIPTION

These functions provide the "inverse" of the C library time routines.


ctime2l takes a strings in the formats

        Mon Jan 12 10:03:55 1986\n\0
        Mon Jan 12 10:03:55 1986\0

representing a local time and and returns a long that is the number of
seconds elapsed since 00:00:00 Jan 1, 1970, Greenwich Mean Time.  This is
the inverse of the C library function ctime.

ctime2tm takes a string in the above format, and returns a structure tm.


date2l takes a date and returns a long that is the number of seconds elapsed
since 00:00:00 Jan 1, 1970, Greenwich Mean Time.  year is the actual year,
e.g. 1986, NOT 86.  month is 1 to 12, NOT 0 to 11.

The string format may end with '\0' or '\n' '\0'.


RETURN VALUE


IMPLEMENTATION


SEE ALSO

C library time functions


NOTE


EXAMPLE

#include <time.h>
#include <tools.h>


main(c, v)
int c;
char **v;
{
    long ltime;
    struct tm *ptm;
    char *p;

    printf("ltime = time(NULL): %ld\n", (ltime = time(NULL)));
    printf("p = ctime(ltime): %s", (p = ctime(&ltime)));

    ptm = localtime(&ltime);
    printf("ptm = localtime(&ltime)\n");
    printf("wday:%d year:%d mon:%d mday:%d yday:%d ",
        ptm->tm_wday, ptm->tm_year, ptm->tm_mon, ptm->tm_mday, ptm->tm_yday);
    printf("hour:%d min:%d sec:%d isdst:%d\n",
        ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ptm->tm_isdst);


    printf("ctime2l(p): %ld\n", ctime2l(p));


    ptm = ctime2tm(p);
    printf("ptm = ctime2tm(p)\n");
    printf("wday:%d year:%d mon:%d mday:%d yday:%d ",
        ptm->tm_wday, ptm->tm_year, ptm->tm_mon, ptm->tm_mday, ptm->tm_yday);
    printf("hour:%d min:%d sec:%d isdst:%d\n",
        ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ptm->tm_isdst);

    printf("date2l(%d, %d, %d, %d, %d, %d): %ld\n",
        ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,
        ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
        date2l(ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,
        ptm->tm_hour, ptm->tm_min, ptm->tm_sec));
}
