Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Time and date

Reply
Thread Tools

Time and date

 
 
raam
Guest
Posts: n/a
 
      05-31-2007
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

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      05-31-2007
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.



 
Reply With Quote
 
 
 
 
Tor Rustad
Guest
Posts: n/a
 
      05-31-2007
On 31 Mai, 07:30, raam <(E-Mail Removed)> 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

 
Reply With Quote
 
Stan Milam
Guest
Posts: n/a
 
      06-03-2007
Tor Rustad wrote:
> On 31 Mai, 07:30, raam <(E-Mail Removed)> 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.
================================================== ===========
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
w3.org suggestion .. page, date, time and topic, date, time code (wish list). Keith Cochrane HTML 2 08-06-2006 06:57 AM
covert time from date Hour min sec format to epoch time i.e time since 1 jan 1970 in C Summu82 C Programming 5 06-07-2006 02:51 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Date & Time chooser for java 1.1 - using only the mouse to select time & date Chris Berg Java 0 10-27-2003 10:59 PM



Advertisments