|
楼主 |
发表于 2004-5-10 16:57:38
|
显示全部楼层
<>函数名: unixtodos
功 能: 把日期和时间转换成DOS格式
用 法: void unixtodos(long utime, struct date *dateptr,
struct time *timeptr);
程序例: <>#include <stdio.h>
#include <dos.h> <>char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; <P>#define SECONDS_PER_DAY 86400L /* the number of seconds in one day */ <P>struct date dt;
struct time tm; <P>int main(void)
{
unsigned long val; <P>/* 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); <P>/* convert date and time to unix format (number of seconds since Jan 1, 1970 */
val = dostounix(&dt, &tm);
/* subtract 42 days worth of seconds */
val -= (SECONDS_PER_DAY * 42); <P>/* 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;
}
</P> |
|