user-0 提问: 怎样用c语言控制时间

回复:
user: user-1
content: linux下有localtime/mktime/time等函数可以调用。

user: user-2
content: boost::date_time...

user: user-3
content: http://bbs.csdn.net/topics/390648646

user: user-4
content: 有时间函数调用

user: user-5
content: 实时刷新获取时间  #include <stdio.h> #include <time.h> #include <unistd.h> int main (void ) {     time_t Curtime;     tm sTime = {0};     while(1)     {            time(&Curtime);          tm *RetTime = localtime( &Curtime );         printf("Time: %04d-%02d-%02d %02d:%02d:%02d \r"                 ,RetTime->tm_year + 1900                 ,RetTime->tm_mon + 1                  ,RetTime->tm_mday                 ,RetTime->tm_hour                 ,RetTime->tm_min                 ,RetTime->tm_sec);         sleep(1);         fflush(stdout);     }         return 0; }

user: user-6
content: 调用时间函数接口即可

user: user-7
content: 这个要调用windows的api。设置一个定时器，没隔一段时间（<=1s）获取一下系统时间，再显示出来。

user: user-8
content: #include <time.h>  #include <stdio.h>  int main( void )  {  time_t t = time(0);  char tmp[64];  strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t) );  puts( tmp );  return 0;  }  size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);   这个可以精确到秒，还有精确去网上找代码，很多了

user: user-3
content: 仅供参考#include <graphics.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dos.h> #include <conio.h> #include <time.h> #include <math.h> time_t t; char timestr1[30];//DDD MMM dd hh:mm:ss YYYY char timestr2[30];//DDD MMM dd hh:mm:ss YYYY char hhmmss[9]; int graphdriver,graphmode,page; int i,xo,yo,r0,r1,r2,r3,r4,r5,r6,r7; int x1,y1,x2,y2; int hh,mm,ss; double c,s; int xasp,yasp; void main() {     xo=60;yo=60;     r0=5; //轴     r1=20;//时针     r2=36;//分针     r3=45;//秒针     r4=50;//时刻度     r5=53;//分刻度     r6=55;//刻度外     r7=59;//表盘     graphdriver=VGA;     graphmode=VGAMED;     initgraph(&graphdriver,&graphmode,"D:\\BC\\BGI");     getaspectratio(&xasp, &yasp);     page=0;     timestr2[0]=0;     while (1) {         if (kbhit()) break;         time(&t);         strcpy(timestr1,ctime(&t));         if (strcmp(timestr1,timestr2)) {             strcpy(timestr2,timestr1);             hh=atoi(timestr2+11);             mm=atoi(timestr2+14);             ss=atoi(timestr2+17);             setvisualpage(page);             setactivepage(1-page);             cleardevice();             sprintf(hhmmss,"%02d:%02d:%02d",hh,mm,ss);             outtextxy(28,0,hhmmss);             pieslice(xo,yo,0,360,r0);             circle(xo,yo,r7);             for (i=0;i<60;i++) {                 c=cos(i*6*3.14159265/180);                 s=sin(i*6*3.14159265/180)*xasp/yasp;                 if (0==(i%5)) {                     x1=xo+r4*c;                     y1=yo+r4*s;                 } else {                     x1=xo+r5*c;                     y1=yo+r5*s;                 } 				x2=xo+r6*c; 				y2=yo+r6*s; 				line(x1,y1,x2,y2); 				if (((hh%12)*5+mm/12+45)%60==i) { 					x2=xo+r1*c; 					y2=yo+r1*s; 					setlinestyle(0,-1,3); 					line(xo,yo,x2,y2); 					setlinestyle(0,-1,1); 				} 				if ((mm+45)%60==i) { 					x2=xo+r2*c; 					y2=yo+r2*s; 					setlinestyle(0,-1,3); 					line(xo,yo,x2,y2); 					setlinestyle(0,-1,1); 				} 				if ((ss+45)%60==i) { 					x2=xo+r3*c; 					y2=yo+r3*s; 					line(xo,yo,x2,y2); 				} 			} 			page=1-page; 		}         delay(100);     }     getch();     closegraph(); }

user: user-9
content: 有时间调用函数的，直接调用就可以了。你可以到资源里找一个做参考，应该有很多。