|
|
 |
 |
 |
 |
Time and date
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 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.
On 31 Mai, 07:30, raam <muthuramantrip@gmail.com> 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 wrote: > On 31 Mai, 07:30, raam <muthuramantrip @gmail.com> 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. =============================================================
|
 |
 |
 |
 |
|