C参考手册
日期与时间 | Date and time
tm
在头文件<time.h>中定义 |
|
|
---|---|---|
struct tm; |
|
|
将日历日期和时间分解为其组件的结构。
会员对象
int tm_sec |
几分钟后 - 0,61 / 0,60note 1 |
---|---|
int tm_min |
一小时后分钟 - 0,59 |
int tm_hour |
自午夜以来的小时 - 0,23 |
int tm_mday |
本月的一天 - 1,31 |
int tm_mon |
自1月 - 11日起的几个月 |
int tm_year |
自1900年以来 |
int tm_wday |
星期天以来的天数 - 0,6 |
int tm_yday |
自1月1日至0日的365天 |
int tm_isdst |
夏令时标志。如果DST有效,则该值为正值,如果不是则为零,如果没有可用信息,则为负值 |
笔记
- 范围允许一个积极的闰秒。不允许在同一分钟内出现两次闰秒(C90范围0..61是缺陷)
例
显示日历时间的开始。
#include <stdio.h>
#include <time.h>
int main(void)
{
struct tm start = {.tm_mday=1};
mktime(&start);
printf("%s\n", asctime(&start));
}
可能的输出:
Mon Jan 1 00:00:00 1900
参考
- C11标准(ISO / IEC 9899:2011):
- 7.27.1 / 3时间分量(p:388)
- C99标准(ISO / IEC 9899:1999):
- 7.23.1 / 3时间的组成部分(p:338)
- C89 / C90标准(ISO / IEC 9899:1990):
- 4.12.1时间的组成部分