confusion about reading time from cmos
Hello everyone: env: Ubuntu 11.04 I write a program reading time from cmos,and the program is as followed: #include <stdio.h> #include <sys/io.h> unsigned char cmos_read(unsigned char addr) { unsigned char tmp = 0; iopl(3); outb(addr,0x70); tmp = inb(0x71); iopl(0); return tmp; } int main(void) { printf("seconds = %x\n",cmos_read(0)); printf("minute = %x\n",cmos_read(2)); printf("hour = %x\n",cmos_read(4)); system("date"); return 0; } and run the program and the result is as followed: wanny@wanny-C-Notebook-XXXX:~$ sudo ./a.out seconds = 9 minute = 42 hour = 7 2012年 06月 12日 星期二 15:42:09 CST question: why the second is right,minute is right , but the hour is different? Thanks in advance!!
Hi! It seems that your CMOS count time in UTC. So, If CST stands for China Standart Time then time zone offset: UTC + 8 hours ;) Best wishes Vladimir Murzin On 6/12/12, 王哲 <wangzhe5004@gmail.com> wrote:
Hello everyone:
env: Ubuntu 11.04
I write a program reading time from cmos,and the program is as followed:
#include <stdio.h> #include <sys/io.h>
unsigned char cmos_read(unsigned char addr) { unsigned char tmp = 0; iopl(3); outb(addr,0x70); tmp = inb(0x71); iopl(0); return tmp; }
int main(void) { printf("seconds = %x\n",cmos_read(0)); printf("minute = %x\n",cmos_read(2)); printf("hour = %x\n",cmos_read(4)); system("date"); return 0; }
and run the program and the result is as followed:
wanny@wanny-C-Notebook-XXXX:~$ sudo ./a.out seconds = 9 minute = 42 hour = 7 2012年 06月 12日 星期二 15:42:09 CST
question: why the second is right,minute is right , but the hour is different?
Thanks in advance!!
2012/6/12 Vladimir Murzin <murzin.v@gmail.com>
Hi!
It seems that your CMOS count time in UTC. So, If CST stands for China Standart Time then time zone offset: UTC + 8 hours ;)
Thanks,and i understand it,Time in cmos is UTC,and the system time is your local time.there is time zone between them. and time in China is earlier 8 hours than UTC,so time in China shoud be UTC + 8. and when you install the ubuntu, ubuntu will let you choose the area where you are,and configure it.and start up the OS and OS read UTC from cmos,then,calculate your local time base on the UTC.
Best wishes
Vladimir Murzin
On 6/12/12, 王哲 <wangzhe5004@gmail.com> wrote:
Hello everyone:
env: Ubuntu 11.04
I write a program reading time from cmos,and the program is as followed:
#include <stdio.h> #include <sys/io.h>
unsigned char cmos_read(unsigned char addr) { unsigned char tmp = 0; iopl(3); outb(addr,0x70); tmp = inb(0x71); iopl(0); return tmp; }
int main(void) { printf("seconds = %x\n",cmos_read(0)); printf("minute = %x\n",cmos_read(2)); printf("hour = %x\n",cmos_read(4)); system("date"); return 0; }
and run the program and the result is as followed:
wanny@wanny-C-Notebook-XXXX:~$ sudo ./a.out seconds = 9 minute = 42 hour = 7 2012年 06月 12日 星期二 15:42:09 CST
question: why the second is right,minute is right , but the hour is different?
Thanks in advance!!
participants (2)
-
Vladimir Murzin -
王哲