First, Introduction
Time processing is often encountered in programming, including program run time and display time. In standard C, date and time processing is included in the header file of time.h and requires the use of a date-and-time-related type of function, which requires import of time.h.
Second, the API
http://www.cnblogs.com/chenqiangjsj/archive/2011/04/06/2007054.html
Third, examples
1. Calculate the time difference
Reference:
http://www.cnblogs.com/fengbohello/p/4153831.html
#include <stdio.h>#include<sys/time.h>#include<unistd.h>intMain () {structtimeval start, end; unsignedLongSpend_time; Gettimeofday (&start, NULL); printf ("Start:%d.%d\n", Start.tv_sec, start.tv_usec); Sleep (1); Gettimeofday (&end, NULL); printf ("End:%d.%d\n", End.tv_sec, end.tv_usec); //microsecond Time DifferenceSpend_time=1000000* (END.TV_SEC-START.TV_SEC) + (end.tv_usec-start.tv_usec); printf ("%ld\n", Spend_time); return 0;}
Compile
gcc -g-o Time_diff TIME_DIFF.C
Run
C Language Time Processing