one, Time function
Copy Code code as follows:
time_t time (time_t *t);
Char *asctime (const struct TM *TM);
Char *asctime_r (const struct TM *tm, char *buf);
Char *ctime (const time_t *TIMEP);
Char *ctime_r (const time_t *TIMEP, char *buf);
struct TM *gmtime (const time_t *TIMEP); Acquired for the British time
struct TM *gmtime_r (const time_t *TIMEP, struct TM *result);
struct TM *localtime (const time_t *TIMEP); Get the local time, pay attention to the difference with English time.
struct TM *localtime_r (const time_t *TIMEP, struct TM *result);
time_t mktime (struct TM *tm);
Double Difftime (time_t time1, time_t TIME0);
int gettimeofday (struct timeval *tv, struct timezone);
int settimeofday (const struct Timeval *tv, const struct timezone);
ii. Setup and acquisition time
Copy Code code as follows:
#include <stdio.h>
#include <time.h>
int main (void)
{
time_t T1;
time_t T2;
struct TM *my_tm;
Char buf[128] = {0};
Number of seconds from epoch (00:00:00 UTC, January 1,1970)
T1 = time (&T1);
printf ("%d\n", T1);
//1355905754
t2 = time (&t2);
Sleep (1);
printf ("%lf\n",
difftime (T2, T1));
//t1,t2 difference: 1.000000, sometimes you can use this function to do the pseudo timer
printf ("%s\n",
CTime (&T1));
//wed Dec 19 16:29:14 2012
Init TM
My_tm->tm_year = 2012-1900;
My_tm->tm_mon = 12-1;
My_tm->tm_mday = 12;
My_tm->tm_hour = 12;
My_tm->tm_min = 12;
My_tm->tm_sec = 12;
//Set time
T1 = mktime (MY_TM);
//Get time
My_tm = LocalTime (&T1);
sprintf (buf, "%04d-%02d-%02d%02d:%02d:%02d",
My_tm->tm_year + 1900, My_tm->tm_mon + 1, my_tm->tm_mday, My_tm->tm_hour, My_tm->tm_min, my_tm->tm_ SEC);
printf ("%s\n", buf);
//2012-12-12 12:12:12
return 0;
}