linux 应用程序设计基础--时间编程

来源:互联网 发布:php apxs2 编辑:程序博客网 时间:2024/05/16 12:57

Theme:时间编程

Author:Jeff.Xue

contact information:contactmexkj@163.com


1.时间类型

UTC ---- 世界标准时间:格林威治时间GMT

日历时间 ---- 从1970-1-1到现在的秒数


2.获得日历时间

#include <time.h>

time_t time(time_t *tloc);


3.时间转换

转化为GMT:struct tm *gmtime(const time_t *timep);

转化为本地时间:struct tm *localtime(const time_t *timep);//注意tm结构


4.时间显示

TM结构转化为字符串:char *asctime(const struct tm *tm);

日历时间转化为字符串:char *ctme(const time_t *timep);


5.从凌晨到现在的时间差:int gettimeofday(struct timeval *tv,struct timezone *tz);


6.延时函数:

unsigned int sleep(second);//秒数

void usleep(mirosecond);//微妙