Microsoft C 5.1 question

John L. Furlani furlani at broadway.UUCP
Sun Jan 15 07:01:22 AEST 1989


In article <104 at rpi.edu>, mcintyre at turing.cs.rpi.edu (David McIntyre) writes:
> 
> 	Could someone give me 2 or 3 sample lines of code showing
> how to print these unsigned dates and times as xx:xx:xx and xx/xx/xxxx
> values?
> 

Here are two functions that do just that when passed the date and time,
respectively.  It should be noted that since DOS stores file times acurate
only to 2 second intervals, seconds are usually left off.  I recommend
looking into purchasing The Waite Group's Microsoft C Bible.  It has all
the 5.1 functions will full usage, compatability, example codes, other
book references for more information on a particular subject, and more.  
I hope these help.

print_sysdate (int date)
{
    unsigned day         = (date & 0x1f);
    unsigned month       = (date >> 5) & 0xf;
    unsigned year        = (date >> 9) & 0x7f;

    printf("%2d/%2d/%2d", day, month, (year + 80));
}

print_systime(int time)
{
    char min_str[5];
    char sec_str[5];
    unsigned second   = (time & 0x1f) * 2;
    unsigned minute   = (time >>  5) & 0x3f;
    unsigned hour     = (time >> 11) & 0x1f;

    if(minute < 10)
        sprintf(min_str, "0%d", minute);
    else
        sprintf(min_str, "%d", minute);

    if(second < 10)
        sprintf(sec_str, "0%d", second);
    else
        sprintf(sec_str, "%d", second);

    printf("%2d:%s:%s", hour, min_str, sec_str);
}

____________
Disclaimer:  "Just blame Me, Myself, and I for it."
John L. Furlani 
The University of South Carolina, Columbia SC
(...!uunet!ncrlnk!ncrcae!broadway!furlani)



More information about the Comp.lang.c mailing list