日期:2014-05-16 浏览次数:20773 次
void * fun()
{
char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
timer_t timep,timep1;
struct tm *p,*p2;
time(&timep);
time(&timep1);
p=gmtime(&timep); //格林威治(GMT)时间
printf("%d%d%d ",(1900+p->tm_year), (1+p->tm_mon),p->tm_mday);
printf("%s %d:%d:%d\n", wday[p->tm_wday], p->tm_hour, p->tm_min, p->tm_sec);
p2=localtime(&timep); /*取得当地时间*/
printf ("%d%d%d ", (1900+p2->tm_year),( 1+p2->tm_mon), p2->tm_mday);
printf("%s %d:%d:%d\n", wday[p2->tm_wday],p2->tm_hour, p2->tm_min, p2->tm_sec);
p2 = NULL;
sleep(2);
while(1)
{
usleep(1000);
p2 = localtime(&timep1);
printf("%d",p2->tm_sec);
if(p2->tm_min ==12 )
printf("time arrived!");
}
}
int main()
{
pthread_t tid;
pthread_create(&tid,NULL,fun,NULL);
while(1);
return 0;
}