?
このドキュメントでは、 php中國(guó)語ネットマニュアル リリース
在頭文件<time.h>中定義 | ||
---|---|---|
time_t mktime(struct tm * time); |
將表示為struct tm
對(duì)象的本地日歷時(shí)間重新規(guī)范化,并將其轉(zhuǎn)換為時(shí)代以來的時(shí)間作為time_t
對(duì)象。time->tm_wday
并被time->tm_yday
忽略。中的數(shù)值time
不檢查超出范圍。
試圖確定夏令時(shí)是否在指定時(shí)間內(nèi)生效的time->tm_isdst
原因的負(fù)值mktime
。
如果轉(zhuǎn)換time_t
成功,time
則修改該對(duì)象。所有字段都會(huì)time
更新以適合其適當(dāng)?shù)姆秶?code>time->tm_wday并time->tm_yday
使用其他領(lǐng)域的信息重新計(jì)算。
時(shí)間 | - | 指向指定本地日歷時(shí)間轉(zhuǎn)換的tm對(duì)象的指針 |
---|
自成立以來的時(shí)間作為time_t
成功的對(duì)象,或者-1
如果time
不能被表示為time_t
對(duì)象(在這種情況下POSIX也需要EOVERFLOW
被存儲(chǔ)errno
)。
如果該struct tm
對(duì)象是從POSIX strptime或等價(jià)函數(shù)獲得的,則其值tm_isdst
是不確定的,并且需要在調(diào)用之前明確設(shè)置mktime
。
#define _POSIX_C_SOURCE 200112L // for setenv on gcc#include <stdlib.h>#include <stdio.h>#include <time.h> int main(void){ setenv("TZ", "/usr/share/zoneinfo/America/New_York", 1); // POSIX-specific struct tm tm = *localtime(&(time_t){time(NULL)}); printf("Today is %s", asctime(&tm)); printf("(DST is %s)\n", tm.tm_isdst ? "in effect" : "not in effect"); tm.tm_mon -= 100; // tm_mon is now outside its normal range mktime(&tm); // tm_dst is not set to -1; today's DST status is used printf("100 months ago was %s", asctime(&tm)); printf("(DST was %s)\n", tm.tm_isdst ? "in effect" : "not in effect");}
輸出:
Today is Fri Apr 22 11:53:36 2016(DST is in effect)100 months ago was Sat Dec 22 10:53:36 2007(DST was not in effect)
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.27.2.3 mktime函數(shù)(p:390-391)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.23.2.3 mktime函數(shù)(p:340-341)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.12.2.3 mktime函數(shù)