}
This program will read the date from the kernel clock and print it out to the standard output stream.
//date.c
//This will read the date from the realtime clock and
//display it on screen.
#include <stdio.h> #include <sys/time.h> #include <unistd.h> void main() {
struct timeval time_val;
//read the date from the realtime clock gettimeofday(&time_val, NULL);
//display the value from the clock
printf(“%s”, ctime((time_t *) &time_val.tv_sec));
}
The following program writes a given date to the kernel clock and then commits it to the hard- ware
//rtc.c
//This program will first set the date on the real time clock
to
//Fri May 25 10:21:00 2001 and then read it back and display
it.
#include <stdio.h> #include <sys/time.h> #include <unistd.h> void main ()
{
struct timeval time_val; struct tm tm_val;
//load the time we are setting into the time structure tm_val.tm_sec = 0;
tm_val.tm_min = 21; tm_val.tm_hour = 10; tm_val.tm_mday = 25; tm_val.tm_mon = 4; tm_val.tm_year = 2001 - 1900; tm_val.tm_wday = 5;
www.amctechcorp.com | 51 |