当前位置: 代码迷 >> C语言 >> 自动设置系统日期
  详细解决方案

自动设置系统日期

热度:342   发布时间:2006-12-07 14:18:39.0
自动设置系统日期

主板电池没电了,保存不了日期,每次开机都要重新设置日期和时间,怎样用C编一个自动设置日期的程序?

搜索更多相关的解决方案: 自动设置  系统  

----------------解决方案--------------------------------------------------------

要设置时间也要知道时间啊!可以通过网络编程,获取时间,但是网络编程还没怎么接触。不过有函数可以设置时间:
函数名: settime
功 能: 设置系统时间
用 法: void settime(struct time *timep);
程序例:

#include <stdio.h>
#include <dos.h>

int main(void)
{
struct time t;

gettime(&t);
printf("The current minute is: %d\n", t.ti_min);
printf("The current hour is: %d\n", t.ti_hour);
printf("The current hundredth of a second is: %d\n", t.ti_hund);
printf("The current second is: %d\n", t.ti_sec);

/* Add one to the minutes struct element and then call settime */
t.ti_min++;
settime(&t);

return 0;
}


----------------解决方案--------------------------------------------------------
做一个SNTP的客户端就可以了 如果LZ需要的话我可以给你一个 不过是我以前在vxworks下做的 ........XP还要改一下
LS的这个没什么用啊 还是要在CMOS下获得时间
----------------解决方案--------------------------------------------------------
问一下
如何获取系统时间呢?
----------------解决方案--------------------------------------------------------
  相关解决方案