您的位置:首页 > 编程语言

国嵌视频学习第二天——时间编程

2012-03-31 19:58 260 查看
时间获取

#include <time.h>

time_t time(time_t *tloc)

功能:获取日历时间,即从1970年1月1日0点到现在所经历的秒数

时间转化

struct tm *gmtime(const time_t *timep)

功能:将日历时间专户为格林威治时间,并保存至TM结构

struct tm *localtime(const time_t *timep)

功能:将日历时间转化为本地时间,保存至TM结构

struct tm{

int tm_sec;

int tm_min;

intt tm_hour;

int tm_mday;本月第几日

int tm_mon;本年第几月

int tm_year;tm_year + 1900 = 哪一年

int tm_wday;本周第几日

int tm_yday;本年第几日

int tm_isdst;日光节约时间

}

时间显示

 char *asctime (const struct tm*tm)

功能:将tm格式的时间转化为字符串,如:Sat Jul 30 08:43:03 2005

char *ctime(const time_t *timep)

功能:将日历时间转化为本地时间的字符串形式

获取时间

int gettimeofday(struct timeval *tv, struct timezone *tz)

功能:获取从今日凌晨到现在的时间差,保存在tv中。常用于计算事件耗时

struct timeval{

int tv_sec; //秒数

     int tv_usec;//微秒数

}

延时执行

unsigned int sleep(unsigned int seconds)

功能:使程序睡眠seconds秒

void usleep(unsigned long usec)

功能:使程序睡眠usec微秒
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  编程 日历