Time and date

Discussion in 'C Programming' started by raam, May 31, 2007.

  1. raam

    raam Guest

    Hello all,
    I am using Turbo c 2.1.
    I have reqritten the timer interrupt in PC as per my requirement.When
    I use gettime() and getdate()
    in my program leter I am not getting current time and date.How to get
    the Time and Date directly from the CMOS.
    Thanks in advance.
    Ram
     
    raam, May 31, 2007
    #1
    1. Advertising

  2. raam wrote:
    > Hello all,
    > I am using Turbo c 2.1.
    > I have reqritten the timer interrupt in PC as per my requirement.When
    > I use gettime() and getdate()
    > in my program leter I am not getting current time and date.How to get
    > the Time and Date directly from the CMOS.
    > Thanks in advance.


    In the C programming language as it is defined, there is no such thing
    as "CMOS". Nor are there such things as gettime() or getdate().

    You get the current time and date with functions declared in <time.h>.
    In particular, you can get the current calendar time with (surprise!)
    the function time(), which returns a variable of type time_t. If all
    you want is a string representing the current time and date, you can use
    ctime() with the value from time() which returns a pointer to a string.

    Here is an example:

    #include <stdio.h>
    #include <time.h>
    int main(void)
    {
    time_t t;
    struct tm tstruct;
    t = time(0);
    tstruct = *localtime(&t);
    printf("The time from ctime is %s", ctime(&t));
    printf("The time from asctime is %s", asctime(&tstruct));
    tstruct.tm_min += 6;
    t = mktime(&tstruct);
    printf("In 6 minutes,\n");
    printf("The time from ctime will be %s", ctime(&t));
    printf("The time from asctime will be %s", asctime(&tstruct));
    return 0;
    }

    [output]
    The time from ctime is Thu May 31 04:52:06 2007
    The time from asctime is Thu May 31 04:52:06 2007
    In 6 minutes,
    The time from ctime will be Thu May 31 04:58:06 2007
    The time from asctime will be Thu May 31 04:58:06 2007


    If you insist on using implementation-specific (and particular
    hardware-specific) things like timer interrupts, CMOS, gettime(), and
    getdate(), then you are not writing code that can be used in any other
    environment, In fact, many of us will not be able to even compile that
    code. Such code is _off-topic_ in <news:comp.lang.c>. You need to
    check your documentation and, if you have problems, check a newsgroup or
    mailing list for your 20-year-old compiler and its non-standard
    functionality, if you can find it.
     
    Martin Ambuhl, May 31, 2007
    #2
    1. Advertising

  3. raam

    Tor Rustad Guest

    On 31 Mai, 07:30, raam <> wrote:
    > Hello all,
    > I am using Turbo c 2.1.


    We don't do specific compilers here.

    > I have reqritten the timer interrupt in PC as per my requirement.When


    We don't do timer interrupts here.

    > I use gettime() and getdate()
    > in my program leter I am not getting current time and date.


    We don't support non-standard C functions.

    > How to get the Time and Date directly from the CMOS.


    We don't access CMOS here.

    Short answer:
    Easy on DOS, more difficult on a modern Windows box.

    Check the IBM-PC spec on CMOS, depending on which OS you use, the "C
    code" will vary, except beeing off-topic here.

    The best place to ask, might be in an assembler programming group
    (they can do C snippets as well).

    --
    Tor
     
    Tor Rustad, May 31, 2007
    #3
  4. raam

    Stan Milam Guest

    Tor Rustad wrote:
    > On 31 Mai, 07:30, raam <> wrote:
    >> Hello all,
    >> I am using Turbo c 2.1.

    >
    > We don't do specific compilers here.


    Okay, but he is just giving you some background information, some
    context if you will.

    >
    >> I have reqritten the timer interrupt in PC as per my requirement.When

    >
    > We don't do timer interrupts here.


    Again, just context information. The OP was not asking how to do
    interrupts.

    >
    >> I use gettime() and getdate()
    >> in my program leter I am not getting current time and date.

    >
    > We don't support non-standard C functions.


    Ditto. But you could civilly say these are non-standard.


    >
    >> How to get the Time and Date directly from the CMOS.

    >
    > We don't access CMOS here.
    >

    Try to write wearing his shoes: He knows you can get the date and time
    using standard functions, but does not know how, and he knows the date
    and time are stored in the CMOS of his computer. He was asking a simple
    direct question, but not the way you wanted to be asked.

    > Short answer:
    > Easy on DOS, more difficult on a modern Windows box.
    >
    > Check the IBM-PC spec on CMOS, depending on which OS you use, the "C
    > code" will vary, except beeing off-topic here.
    >
    > The best place to ask, might be in an assembler programming group
    > (they can do C snippets as well).
    >

    This was more helpful. My answer would be to explore the functions in
    <time.h>. Specifically, the types time_t, the functions time() and
    localtime(), and possibly ctime()
    > --
    > Tor
    >



    --
    Regards,
    Stan Milam
    =============================================================
    Charter Member of The Society for Mediocre Guitar Playing on
    Expensive Instruments, Ltd.
    =============================================================
     
    Stan Milam, Jun 3, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    619
    Matthew Speed
    Nov 8, 2003
  2. Chris Berg
    Replies:
    0
    Views:
    810
    Chris Berg
    Oct 27, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,302
    Michael Borgwardt
    May 30, 2004
  4. Keith Cochrane
    Replies:
    2
    Views:
    631
    Keith Cochrane
    Aug 6, 2006
  5. Summu82
    Replies:
    5
    Views:
    877
    Richard Heathfield
    Jun 7, 2006
Loading...

Share This Page