time_t mktime (struct tm *__tp)
/* ISO C `broken-down time' structure. */
struct tm
{
int tm_sec; /* Seconds. [0-60] (1 leap second) */
int tm_min; /* Minutes. [0-59] */
int tm_hour; /* Hours. [0-23] */
int tm_mday; /* Day. [1-31] */
int tm_mon; /* Month. [0-11] */
int tm_year; /* Year - 1900. */
int tm_wday; /* Day of week. [0-6] */
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/
# ifdef __USE_MISC
long int tm_gmtoff; /* Seconds east of UTC. */
const char *tm_zone; /* Timezone abbreviation. */
# else
long int __tm_gmtoff; /* Seconds east of UTC. */
const char *__tm_zone; /* Timezone abbreviation. */
# endif
};
Broken-down Time (The GNU C Library)
对tm结构体的注释ISO C `broken-down time' structure.
说明是ISO标准的C时间分解结构。值得注意的是这个是ISO标准的。
上面连接里有一句话:
The
mktimefunction ignores the specified contents of thetm_wday,tm_yday,tm_gmtoff, andtm_zonemembers of the broken-down time structure.
mktime在传参时会忽略 tm_wday, tm_yday, tm_gmtoff和 tm_zone。我们先暂时不管。
对于tm_sec,tm_min,tm_hour,tm_mday,tm_mon,tm_year;这几个参数,好理解,就是需要转换的年月日。
对于tm_isdst表示是否是夏令时,通过网上查询可知,我国只在1986年到1991实时过夏令时。因此这里可以传0,表示不是夏令时。
mktime不使用tm_gmtoff和 tm_zone来说明时区,而是使用tzset函数来说明时区,mktime会根据tzset设置的时区信息来初始化tm_gmtoff和 tm_zone。
Calling
mktimealso sets the current time zone as iftzsetwere called;mktimeuses this information instead of brokentime’s initialtm_gmtoffandtm_zonemembers. See Functions and Variables for Time Zones.
对于tm_wday, tm_yday,则会根据tm结构的其他字段被mktime函数改变。如下是mktime的man说明
The mktime() function modifies the fields of the tm structure as follows: tm_wday and tm_yday are set to values determined from the contents of the other fields;
最后,一般使用时就把tm_sec,tm_min,tm_hour,tm_mday,tm_mon,tm_year,外加tm_isdst这几个参数赋值即可。
最后
以上就是坚定冰棍最近收集整理的关于mktime 传参struct tm赋值说明的全部内容,更多相关mktime内容请搜索靠谱客的其他文章。
发表评论 取消回复