?
? ????? PHP ??? ???? ??? ?? ??
在頭文件<time.h>中定義 | ||
---|---|---|
time_t mktime(struct tm * time); |
將表示為struct tm
對象的本地日歷時間重新規(guī)范化,并將其轉(zhuǎn)換為時代以來的時間作為time_t
對象。time->tm_wday
并被time->tm_yday
忽略。中的數(shù)值time
不檢查超出范圍。
試圖確定夏令時是否在指定時間內(nèi)生效的time->tm_isdst
原因的負值mktime
。
如果轉(zhuǎn)換time_t
成功,time
則修改該對象。所有字段都會time
更新以適合其適當?shù)姆秶?code>time->tm_wday并time->tm_yday
使用其他領(lǐng)域的信息重新計算。
時間 | - | 指向指定本地日歷時間轉(zhuǎn)換的tm對象的指針 |
---|
自成立以來的時間作為time_t
成功的對象,或者-1
如果time
不能被表示為time_t
對象(在這種情況下POSIX也需要EOVERFLOW
被存儲errno
)。
如果該struct tm
對象是從POSIX strptime或等價函數(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標準(ISO / IEC 9899:2011):
7.27.2.3 mktime函數(shù)(p:390-391)
C99標準(ISO / IEC 9899:1999):
7.23.2.3 mktime函數(shù)(p:340-341)
C89 / C90標準(ISO / IEC 9899:1990):
4.12.2.3 mktime函數(shù)