系统时间与日期函数如下:
函数名 | 功能 |
asctime | 将时间和日期以字符串格式表示 |
ctime | 将时间和日期以字符串格式表示 |
gettimeofday | 取得目前的时间 |
localtime | 取得当地目前时间和日期,并转换成真实世界的时间日期表示方法 |
mktime | 将时间结构数据转换成经过的秒数 |
settimeofday | 设置目前时间 |
time | 取得目前时间 |
gmtime | 取得目前时间和日期 |
以后再贴实现代码。
下面是相关的数据结构:
- struct tm
- struct tm
- {
- int tm_sec;
- int tm_min;
- int tm_hour;
- int tm_mday;
- int tm_mon;
- int tm_year;
- int tm_wday;
- int tm_yday;
- int tm_isdst;
- };
Member | Meaning | Range |
---|---|---|
tm_sec | seconds after the minute | 0-61* |
tm_min | minutes after the hour | 0-59 |
tm_hour | hours since midnight | 0-23 |
tm_mday | day of the month | 1-31 |
tm_mon | months since January | 0-11 |
tm_year | years since 1900 | |
tm_wday | days since Sunday | 0-6 |
tm_yday | days since January 1 | 0-365 |
tm_isdst | Daylight Saving Time flag |
- struct timeval
- struct timeval
- {
- long tv_sec; //second
- long tv_usec; //microsecond
- };
- struct timezone
- struct timezone
- {
- int tz_minuteswest;//和Greenwich 时间差了多少分钟
- int tz_dsttime;//日光节约时间的状态
- };
- time_t,clock_t
翻译:
time_t通常被认为是一个整数值,表示从1970年1月1日 00:00起(用UTC表示)到现在的时间间隔。这是历史原因造成的,因为它对应UNIX时间戳,但是却广泛地被跨平台实现C库。
clock_t is a type that capable of representing clock tick counts and support arithmetical operations.This type is returned by the clock function of the <ctime> header to represent the number of click ticks since the beginning of the program execution.
翻译:
clock_t 类型表示时钟节拍,支持算术运算。定义在ctime.h头文件的clock函数的返回值就是这种类型的,它表示自程序开始运行以来所经过的节拍数。