日期:2014-05-16 浏览次数:20750 次
一、时间函数
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); //获取的为英国时间
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime(const time_t *timep); //获取的为本地时间,注意与英国时间的区别。
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 *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);
二、设置和获取时间
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t1;
time_t t2;
struct tm *my_tm;
char buf[128] = {0};
//自Epoch (00:00:00 UTC, January 1,1970)的秒数