Search code examples
ctimeturbo-c

Get current time in BORLAND c


I saw somewhere that someone took the computer's current in a whole int,and started calculating hours minutes seconds,and i don't remember what function he used to get the time as an int, maybe inportb or MK_FP or something else,and i don't remember if it was in dos.h.Can someone help me,i tried to find this for some quite time.


Solution

  • In standard C, you can get the current time by calling the time function:

    time_t now = time(NULL);
    

    which requires

    #include <time.h>
    

    The NULL argument is admittedly odd; it's there for historical reasons.

    time_t is a numeric type capable of representing times. The way it does so is implementation-specific, but it's typically an integer representing the number of seconds since January 1, 1970. I'm not certain that Borland uses the same representation; consult your system's documentation for the time function.

    <time.h> also provides various functions to convert between time_t values and struct tm (a "broken-down" time), to generate human-readable strings from times, and so forth.

    There may be some other way to get the current time, something specific to Borland and/or MS-DOS. But unless you need better than 1-second resolution, or you're using an implementation that's so ancient it doesn't suport the time function properly, there's not much reason to use anything other than the standard time function.