RAD Studio |  |

unixtodos

Header File

dos.h

Category

Time and Date Routines

Prototype

void unixtodos(long time, struct date *d, struct time *t);

Description

Converts date and time from UNIX to DOS format.

unixtodos converts the UNIX-format time given in time to DOS format and fills in the date and time structures pointed to by d and t.

time must not represent a calendar time earlier than Jan. 1, 1980 00:00:00.

Return Value

None.

Example

Copy Code

    #include <stdio.h>
    #include <dos.h>
    char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    #define SECONDS_PER_DAY 86400L  /* the number of seconds in one day */
    struct date dt;
    struct time tm;
    int main(void)
    {
       unsigned long val;
    /* get today's date and time */
       getdate(&dt);
       gettime(&tm);
       printf("today is %d %s %d\n", dt.da_day, month[dt.da_mon], dt.da_year);
    /*convert date and time to unix format (num of seconds since Jan 1, 1970*/
       val = dostounix(&dt, &tm);
    /* subtract 42 days worth of seconds */
       val -= (SECONDS_PER_DAY * 42);
    /* convert back to dos time and date */
       unixtodos(val, &dt, &tm);
       printf("42 days ago it was %d %s %d\n",
              dt.da_day, month[dt.da_mon], dt.da_year);
       return 0;
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
| + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!