#include/* puts, printf */#include /* time_t, struct tm, time, localtime */int main (){ struct tm * timeinfo; double seconds; time_t start_time,now; time (&start_time); while(1){ time (&now); seconds = difftime(now,start_time); if(seconds==5){ break; } } timeinfo = localtime (&start_time); printf ("start_time local time and date: %s", asctime(timeinfo)); timeinfo = localtime (&now); printf ("now local time and date: %s", asctime(timeinfo)); printf("time spend %f\n",seconds); return 0;}
输出
start_time local time and date: Fri May 24 10:24:40 2019now local time and date: Fri May 24 10:24:45 2019time spend 5.000000