?
本文檔使用 PHP中文網(wǎng)手冊(cè) 發(fā)布
在頭文件<time.h>中定義 | ||
---|---|---|
size_t strftime(char * str,size_t count,const char * format,const struct tm * time); | (直到C99) | |
size_t strftime(char * restrict str,size_t count,const char * restrict format,const struct tm * restrict time); | (自C99以來(lái)) |
根據(jù)格式字符串將日期和時(shí)間信息從給定日歷時(shí)間轉(zhuǎn)換time
為以空字符結(jié)尾的多字節(jié)str
字符串format
。最多count
寫入字節(jié)。
海峽 | - | 指向char數(shù)組的第一個(gè)元素的輸出 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
計(jì)數(shù) | - | 最大寫入字節(jié)數(shù) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
格式 | - | 指向以空字符結(jié)尾的多字節(jié)字符串指定轉(zhuǎn)換格式的指針。格式字符串由零個(gè)或多個(gè)轉(zhuǎn)換說(shuō)明符和普通字符(除%以外)組成。所有普通字符(包括終止空字符)都將被復(fù)制到輸出字符串而不進(jìn)行修改。每個(gè)轉(zhuǎn)換規(guī)范都以%字符開頭,可以選擇后跟E或O修飾符(如果語(yǔ)言環(huán)境不支持,則忽略),后面跟著決定說(shuō)明符行為的字符。以下格式說(shuō)明符可用:轉(zhuǎn)換說(shuō)明符說(shuō)明使用的字段%寫入文字%。完整的轉(zhuǎn)換規(guī)范必須是%%。n(C99)寫入換行符t(C99)寫入水平制表符年份Y以十進(jìn)制數(shù)字寫年,例如 在IS0 8601周內(nèi)從星期一開始,每年的第一周必須滿足以下要求:包括1月4日包括今年的第一個(gè)星期四tm_year,tm_wday,tm_yday g(C99)寫出ISO 8601以星期為基礎(chǔ)的年份的最后2位數(shù)字,即包含指定周的年份(范圍00,99)。在IS0 8601周內(nèi)從星期一開始,并且一年中的第一周必須滿足以下要求:包括1月4日包括今年的第一個(gè)星期四tm_year,tm_wday,tm_yday月份b寫出縮寫月份名稱,例如Oct(區(qū)域依賴)tm_mon h( C99)b的同義詞tm_mon B寫完整的月份名稱,例如10月(取決于語(yǔ)言環(huán)境)tm_mon m將月份寫為十進(jìn)制數(shù)字(范圍01,12)tm_mon Om(C99)使用替代數(shù)字系統(tǒng)寫月 十二而不是12 ja_JP locale tm_mon周U寫一年中的一周作為十進(jìn)制數(shù)(星期日是一周的第一天)(范圍00,53)tm_year,tm_wday,tm_yday OU(C99)寫一年的周,如%U,使用替代數(shù)字系統(tǒng),例如五十二,而不是ja_JP語(yǔ)言環(huán)境中的52,tm_year,tm_wday,tm_yday W將年份的星期寫為十進(jìn)制數(shù)(星期一是一周中的第一天)(范圍00 ,53)tm_year,tm_wday,tm_yday OW(C99)使用替代數(shù)字系統(tǒng)(例如五十二而不是52)在ja_JP locale tm_year,tm_wday,tm_yday V(C99)中寫入ISO一年中的8601周(范圍01,53)。在IS0 8601周內(nèi)從星期一開始,一年的第一周必須滿足以下要求:包括1月4日包括今年的第一個(gè)星期四tm_year,tm_wday,tm_yday OV(C99)寫入年份的星期,如%V,使用替代數(shù)字系統(tǒng),例如五十二,而不是ja_JP語(yǔ)言環(huán)境中的52,tm_year,tm_wday,tm_yday每年的月份/月份j作為十進(jìn)制數(shù)字(范圍001,366)寫入一年中的某一天tm_yday d以十進(jìn)制數(shù)字形式顯示月份的日期(范圍為01,31)tm_mday Od(C99)寫入月份的零基日期使用替代數(shù)字系統(tǒng),例如ja_JP語(yǔ)言環(huán)境中的二十七而不是23單個(gè)字符前面有一個(gè)空格。tm_mday e(C99)將月份中的某一天寫為十進(jìn)制數(shù)(范圍為1,31)。單個(gè)數(shù)字前面有一個(gè)空格。tm_mday Oe(C99)使用替代數(shù)字系統(tǒng)編寫一個(gè)月的一天,例如 二十七而不是ja_JP語(yǔ)言環(huán)境中的27單個(gè)字符前面有一個(gè)空格。tm_mday一周中的某天寫一個(gè)縮寫星期幾名稱,例如Fri(區(qū)域設(shè)置相關(guān))tm_wday A寫出完整的星期幾名稱,例如星期五(區(qū)域設(shè)置相關(guān))tm_wday w寫入星期幾作為十進(jìn)制數(shù)字,其中星期日為0(范圍0-6)tm_wday Ow(C99)使用替代數(shù)字系統(tǒng)(例如ja_JP區(qū)域設(shè)置tm_wday u(C99)將工作日寫為十進(jìn)制數(shù),其中星期一為1(ISO 8601格式)(范圍1 -7)tm_wday Ou(C99)使用替代數(shù)字系統(tǒng)寫入星期幾,其中星期一為1,例如ja_JP語(yǔ)言環(huán)境中的二代替2代表tm_wday小時(shí),分鐘,秒H將小時(shí)數(shù)寫為十進(jìn)制數(shù), | 轉(zhuǎn)換說(shuō)明符 | 說(shuō)明 | 使用的字段 | % | 寫文字%。完整的轉(zhuǎn)換規(guī)范必須是%%。 | N(C99) | 寫換行符 | 噸(C99) | 寫水平制表符 | 年 | 和 | 將年份寫成十進(jìn)制數(shù)字,例如2017 | tm_year | 安永(C99) | 在替代表示中寫入年份,例如平成23年(平成23年)而不是2011年(2011年)在ja_JP語(yǔ)言環(huán)境中 | tm_year | 和 | 寫一年的最后兩位數(shù)作為十進(jìn)制數(shù)(范圍00,99) | tm_year | Oy(C99) | 使用替代數(shù)字系統(tǒng)寫入年份的最后兩位數(shù)字,例如ja_JP語(yǔ)言環(huán)境中的十一而不是11 | tm_year | Ey(C99) | 將年份寫入與區(qū)域設(shè)置的備選日歷周期的偏移%EC(區(qū)域依賴) | tm_year | C(C99) | 將年份的前兩位數(shù)字作為十進(jìn)制數(shù)字(范圍為00,99) | tm_year | EC(C99) | 在地區(qū)的替代表示中寫入基準(zhǔn)年(期間)的名稱,例如ja_JP中的平成(平成時(shí)代) | tm_year | G(C99) | writes ISO 8601 week-based year, i.e. the year that contains the specified week. In IS0 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements: Includes January 4 Includes first Thursday of the year | tm_year, tm_wday, tm_yday | g(C99) | writes last 2 digits of ISO 8601 week-based year, i.e. the year that contains the specified week (range 00,99). In IS0 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements: Includes January 4 Includes first Thursday of the year | tm_year, tm_wday, tm_yday | Month | b | writes abbreviated month name, e.g. Oct (locale dependent) | tm_mon | h(C99) | synonym of b | tm_mon | B | writes full month name, e.g. October (locale dependent) | tm_mon | m | writes month as a decimal number (range 01,12) | tm_mon | Om(C99) | writes month using the alternative numeric system, e.g. 十二 instead of 12 in ja_JP locale | tm_mon | Week | U | writes week of the year as a decimal number (Sunday is the first day of the week) (range 00,53) | tm_year, tm_wday, tm_yday | OU(C99) | writes week of the year, as by %U, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP locale | tm_year, tm_wday, tm_yday | W | writes week of the year as a decimal number (Monday is the first day of the week) (range 00,53) | tm_year, tm_wday, tm_yday | OW(C99) | writes week of the year, as by %W, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP locale | tm_year, tm_wday, tm_yday | V(C99) | writes ISO 8601 week of the year (range 01,53). In IS0 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements: Includes January 4 Includes first Thursday of the year | tm_year, tm_wday, tm_yday | OV(C99) | writes week of the year, as by %V, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP locale | tm_year, tm_wday, tm_yday | Day of the year/month | j | writes day of the year as a decimal number (range 001,366) | tm_yday | d | writes day of the month as a decimal number (range 01,31) | tm_mday | Od(C99) | writes zero-based day of the month using the alternative numeric system, e.g 二十七 instead of 23 in ja_JP locale Single character is preceded by a space. | tm_mday | e(C99) | writes day of the month as a decimal number (range 1,31). Single digit is preceded by a space. | tm_mday | Oe(C99) | writes one-based day of the month using the alternative numeric system, e.g. 二十七 instead of 27 in ja_JP locale Single character is preceded by a space. | tm_mday | Day of the week | a | writes abbreviated weekday name, e.g. Fri (locale dependent) | tm_wday | A | writes full weekday name, e.g. Friday (locale dependent) | tm_wday | w | writes weekday as a decimal number, where Sunday is 0 (range 0-6) | tm_wday | Ow(C99) | writes weekday, where Sunday is 0, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP locale | tm_wday | u(C99) | writes weekday as a decimal number, where Monday is 1 (ISO 8601 format) (range 1-7) | tm_wday | Ou(C99) | writes weekday, where Monday is 1, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP locale | tm_wday | Hour, minute, second | H | writes hour as a decimal number, 24 hour clock (range 00-23) | tm_hour | OH(C99) | writes hour from 24-hour clock using the alternative numeric system, e.g. 十八 instead of 18 in ja_JP locale | tm_hour | I | writes hour as a decimal number, 12 hour clock (range 01,12) | tm_hour | OI(C99) | writes hour from 12-hour clock using the alternative numeric system, e.g. 六 instead of 06 in ja_JP locale | tm_hour | M | writes minute as a decimal number (range 00,59) | tm_min | OM(C99) | writes minute using the alternative numeric system, e.g. 二十五 instead of 25 in ja_JP locale | tm_min | S | writes second as a decimal number (range 00,60) | tm_sec | OS(C99) | writes second using the alternative numeric system, e.g. 二十四 instead of 24 in ja_JP locale | tm_sec | Other | c | writes standard date and time string, e.g. Sun Oct 17 04:41:13 2010 (locale dependent) | all | Ec(C99) | writes alternative date and time string, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale | all | x | writes localized date representation (locale dependent) | all | Ex(C99) | writes alternative date representation, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale | all | X | writes localized time representation (locale dependent) | all | EX(C99) | writes alternative time representation (locale dependent) | all | D(C99) | equivalent to "%m/%d/%y" | tm_mon, tm_mday, tm_year | F(C99) | equivalent to "%Y-%m-%d" (the ISO 8601 date format) | tm_mon, tm_mday, tm_year | r(C99) | 寫本地化的12小時(shí)時(shí)鐘時(shí)間(取決于語(yǔ)言環(huán)境) | tm_hour,tm_min,tm_sec | R(C99) | 相當(dāng)于“%H:%M” | tm_hour,tm_min | T(C99) | 相當(dāng)于“%H:%M:%S”(ISO 8601時(shí)間格式) | tm_hour,tm_min,tm_sec | p | 寫本地化的上午或下午(區(qū)域依賴) | tm_hour | 與(C99) | 以ISO 8601格式(例如-0430)寫入U(xiǎn)TC的偏移量,如果時(shí)區(qū)信息不可用,則不寫入字符 | tm_isdst的 | 同 | 寫時(shí)區(qū)名稱或縮寫,或者如果時(shí)區(qū)信息不可用,則不包含字符(取決于語(yǔ)言環(huán)境) | tm_isdst的 | |||
轉(zhuǎn)換說(shuō)明符 | 說(shuō)明 | 使用的字段 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
% | 寫文字%。完整的轉(zhuǎn)換規(guī)范必須是%%。 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
N(C99) | 寫換行符 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
噸(C99) | 寫水平制表符 |
| 年份|
| Y | 將年份寫為十進(jìn)制數(shù)字,例如2017 | tm_year |
| EY(C99)| 在替代表示中寫入年份,例如平成23年(平成23年)而不是2011年(2011年)在ja_JP地區(qū)| tm_year |
| y | 將年份的最后2位數(shù)字寫為十進(jìn)制數(shù)(范圍為00,99)| tm_year |
| Oy(C99)| 使用替代數(shù)字系統(tǒng)寫入年份的最后2位數(shù)字,例如ja_JP locale |中的十一而不是11 tm_year |
| Ey(C99)| 將年份寫入與區(qū)域設(shè)置的替代日歷期%EC(區(qū)域依賴)|的偏移量 tm_year |
| C(C99)| 寫一年的前兩位數(shù)作為十進(jìn)制數(shù)(范圍為00,99)| tm_year |
| EC(C99)| 在地區(qū)的替代表示中寫入基準(zhǔn)年(期間)的名稱,例如平成(平成時(shí)代)in ja_JP | tm_year |
| G(C99)| 寫ISO 8601以周為基礎(chǔ)的年份,即包含指定周的年份。在IS0 8601周內(nèi)從星期一開始,并且一年中的第一周必須滿足以下要求:包括1月4日包括今年的第一個(gè)星期四| tm_year,tm_wday,tm_yday |
| g(C99)| 寫出ISO 8601以周為單位的年份的最后2位數(shù)字,即包含指定周的年份(范圍00,99)。在IS0 8601周內(nèi)從星期一開始,并且一年中的第一周必須滿足以下要求:包括1月4日包括今年的第一個(gè)星期四| tm_year,tm_wday,tm_yday |
| 月|
| b | 寫出縮寫的月份名稱,例如Oct(區(qū)域依賴)| tm_mon |
| h(C99)| b |的同義詞 tm_mon |
| B | 寫完整的月份名稱,例如10月(取決于語(yǔ)言環(huán)境)| tm_mon |
| m | 將月份作為十進(jìn)制數(shù)字(范圍為01,12)|寫入 tm_mon |
| Om(C99)| 使用替代數(shù)字系統(tǒng)寫月份,例如ja_JP locale |中的十二而不是12 tm_mon |
| 星期|
| U | 寫一年中的一周作為十進(jìn)制數(shù)(星期日是一周中的第一天)(范圍00,53)| tm_year,tm_wday,tm_yday |
| OU(C99)| 寫一年中的一周,如%U,使用替代數(shù)字系統(tǒng),例如五十二而不是ja_JP語(yǔ)言環(huán)境中的52。tm_year,tm_wday,tm_yday |
| W | 寫一年中的一周作為十進(jìn)制數(shù)(星期一是一周中的第一天)(范圍00,53)| tm_year,tm_wday,tm_yday |
| OW(C99)| 用%W寫出一年中的第一周,使用替代數(shù)字系統(tǒng),例如ja_JP語(yǔ)言環(huán)境中的五十二而不是52。tm_year,tm_wday,tm_yday |
| V(C99)| 寫一年的ISO 8601周(范圍01,53)。在IS0 8601周內(nèi)從星期一開始,并且一年中的第一周必須滿足以下要求:包括1月4日包括今年的第一個(gè)星期四| tm_year,tm_wday,tm_yday |
| OV(C99)| 寫出一年中的一周,如%V所示,使用替代數(shù)字系統(tǒng),例如ja_JP語(yǔ)言環(huán)境中的五十二而不是52。tm_year,tm_wday,tm_yday |
| 一年中的每月|
| j | 寫一年中的一天作為十進(jìn)制數(shù)(范圍001,366)| tm_yday |
| d | 將月份的日期寫為十進(jìn)制數(shù)(范圍為01,31)| tm_mday |
| Od(C99)| 使用替代數(shù)字系統(tǒng)寫出從零開始的一天的日期,例如ja_JP語(yǔ)言環(huán)境中的二十七而不是23。單個(gè)字符前面有一個(gè)空格。| tm_mday |
| e(C99)| 將月份的日期寫為十進(jìn)制數(shù)(范圍1,31)。單個(gè)數(shù)字前面有一個(gè)空格。| tm_mday |
| Oe(C99)| 使用替代數(shù)字系統(tǒng)寫一個(gè)月的一天,例如ja_JP語(yǔ)言環(huán)境中的二十七而不是27。單個(gè)字符前面有一個(gè)空格。| tm_mday |
| 一周中的星期幾|
| a | 寫縮寫的星期幾名稱,例如Fri(locale dependent)| tm_wday |
| A | 寫完整的星期幾名稱,例如Friday(locale dependent)| tm_wday |
| w | 寫星期幾作為十進(jìn)制數(shù),星期日為0(范圍0-6)| tm_wday |
| Ow(C99)| 寫星期幾,星期日為0,使用替代數(shù)字系統(tǒng),例如ja_JP locale |中的二而不是2 tm_wday |
| 你(C99)| 寫星期幾作為十進(jìn)制數(shù),星期一為1(ISO 8601格式)(范圍1-7)| tm_wday |
| Ou(C99)| 寫星期幾,星期一為1,使用替代數(shù)字系統(tǒng),例如ja_JP locale |中的二而不是2 tm_wday |
| 小時(shí),分鐘,秒|
| H | 將小時(shí)數(shù)寫為十進(jìn)制數(shù),24小時(shí)制(范圍00-23)| tm_hour |
| OH(C99)| 使用替代數(shù)字系統(tǒng)從24小時(shí)制寫小時(shí),例如ja_JP locale |中的十八而不是18 tm_hour |
| 我| 將小時(shí)數(shù)寫為十進(jìn)制數(shù),12小時(shí)制(范圍01,12)| tm_hour |
| OI(C99)| 使用替代數(shù)字系統(tǒng)從12小時(shí)時(shí)鐘寫入小時(shí),例如ja_JP locale中的六而不是06 tm_hour |
| M | 將分鐘寫入十進(jìn)制數(shù)(范圍為00,59)| tm_min |
| OM(C99)| 使用替代數(shù)字系統(tǒng)寫分鐘,例如ja_JP locale |中的二十五而不是25 tm_min |
| S | 寫第二個(gè)作為十進(jìn)制數(shù)(范圍00,60)| tm_sec |
| OS(C99)| 使用替代數(shù)字系統(tǒng)寫第二個(gè),例如ja_JP locale |中的二十四而不是24 tm_sec |
| 其他|
| c | 寫標(biāo)準(zhǔn)的日期和時(shí)間字符串,例如Sun 10月17日04:41:13 2010(取決于語(yǔ)言環(huán)境)| 全部|
| Ec(C99)| 寫替代日期和時(shí)間字符串,例如在ja_JP語(yǔ)言環(huán)境中使用平成23年(平成23年)而不是2011年(2011年)全部|
| x | 寫本地化的日期表示法(依賴于語(yǔ)言環(huán)境)| 全部|
| Ex(C99)| 寫替代日期表示法,例如在ja_JP語(yǔ)言環(huán)境中使用平成23年(平成23年)而不是2011年(2011年)全部|
| X | 寫本地化的時(shí)間表示(區(qū)域依賴)| 全部|
| EX(C99)| 寫入替代時(shí)間表示(取決于語(yǔ)言環(huán)境)| 全部|
| D(C99)| 相當(dāng)于“%m /%d /%y”| tm_mon,tm_mday,tm_year |
| F(C99)| 相當(dāng)于“%Y-%m-%d”(ISO 8601日期格式)| tm_mon,tm_mday,tm_year |
| r(C99)| 寫本地化的12小時(shí)時(shí)鐘時(shí)間(取決于語(yǔ)言環(huán)境)| tm_hour,tm_min,tm_sec |
| R(C99)| 相當(dāng)于“%H:%M”| tm_hour,tm_min |
| T(C99)| 相當(dāng)于“%H:%M:%S”(ISO 8601時(shí)間格式)| tm_hour,tm_min,tm_sec |
| p | 寫本地化的上午或下午(區(qū)域依賴)| tm_hour |
| z(C99)| 寫入ISO 8601格式的UTC偏移量(例如-0430),如果時(shí)區(qū)信息不可用,則不顯示字符| tm_isdst |
| Z | 寫時(shí)區(qū)名稱或縮寫,或者如果時(shí)區(qū)信息不可用(取決于語(yǔ)言環(huán)境),則為無(wú)字符| tm_isdst |
| 時(shí)間| - | 指向結(jié)構(gòu)tm對(duì)象的指針,指定格式化為|的時(shí)間
包括1月4日
包括一年的第一個(gè)星期四
tm_year
, tm_wday
, tm_yday
g
(C99)寫出ISO 8601以周為單位的年份的后兩位數(shù)字,即包含指定周(范圍[00,99]
)的年份。在IS0 8601周內(nèi)從星期一開始,一年的第一周必須滿足以下要求:
包括1月4日
包括一年的第一個(gè)星期四
tm_year
,tm_wday
,tm_yday
月 b
寫縮寫的月份名稱,例如Oct
(位置有關(guān)) tm_mon
h
(C99)b
tm_mon
B
寫完整月份名稱的同義詞,例如October
(區(qū)域設(shè)置相關(guān)) tm_mon
m
將月份寫為十進(jìn)制數(shù)(范圍[01,12]
) tm_mon
Om
(C99)寫道月使用可替代數(shù)字系統(tǒng),如十二代替12 Ja_JP表示區(qū)域 tm_mon
周 U
寫了一年的星期為十進(jìn)制數(shù)(星期日是一周的第一天)(范圍[00,53]
) tm_year
,tm_wday
,tm_yday
OU
(C99)寫道一周年通過(guò),%U
使用替代的數(shù)字系統(tǒng),如五十二,而不是在Ja_JP表示區(qū)域52 tm_year
,tm_wday
,tm_yday
W
寫了一年的星期為十進(jìn)制數(shù)(星期一是一周的第一天)(范圍[00,53]
) tm_year
,tm_wday
,tm_yday
OW
(C99)寫道星期的一年,通過(guò)%W
使用替代的數(shù)字系統(tǒng),如五十二,而不是在Ja_JP表示區(qū)域52 tm_year
,tm_wday
,tm_yday
V
(C99)寫入一年中的ISO 8601周(范圍[01,53]
)。在IS0 8601周內(nèi)從星期一開始,一年的第一周必須滿足以下要求:
包括1月4日
包括一年的第一個(gè)星期四
tm_year
, tm_wday
, tm_yday
OV
(C99)寫入周一年中通過(guò),%V
使用替代的數(shù)字系統(tǒng),例如五十二代替Ja_JP表示區(qū)域52 tm_year
,tm_wday
,tm_yday
年/月的日 j
寫入一年中的哪一天為十進(jìn)制數(shù)(范圍[001,366]
) tm_yday
d
寫入日作為十進(jìn)制數(shù)(范圍[01,31]
) 的月份tm_mday
Od
(C99)使用替代數(shù)字系統(tǒng)編寫月份的零基日期,例如ja_JP語(yǔ)言環(huán)境中的二十七而不是23。單個(gè)字符前面有一個(gè)空格。
tm_mday
e
(C99)以十進(jìn)制數(shù)(范圍)的形式寫入當(dāng)月的某天[1,31]
。單個(gè)數(shù)字前面有一個(gè)空格。
tm_mday
Oe
(C99)使用替代數(shù)字系統(tǒng)寫一個(gè)月的一天,例如ja_JP語(yǔ)言環(huán)境中的二十七而不是27。單個(gè)字符前面有一個(gè)空格。
tm_mday
星期 a
寫簡(jiǎn)寫的星期名稱,例如Fri
(位置有關(guān)) tm_wday
A
寫完整的星期幾的名稱,如Friday
(位置有關(guān)) tm_wday
w
寫入平日的十進(jìn)制數(shù),星期日為0
(范圍[0-6]
) tm_wday
Ow
(C99)使用替代數(shù)字系統(tǒng)寫周日,其中星期日是0
,例如ja_JP語(yǔ)言環(huán)境中的二而不是2 tm_wday
u
(C99)將星期幾寫為十進(jìn)制數(shù),星期一為1
(ISO 8601格式)(范圍[1-7]
) tm_wday
Ou
(C99)寫入平日,其中星期一是1
,使用備選數(shù)字系統(tǒng),例如,二,而不是在區(qū)域設(shè)置Ja_JP表示2 tm_wday
時(shí),分,秒 H
寫入小時(shí)為十進(jìn)制數(shù),24小時(shí)時(shí)鐘(范圍[00-23]
) tm_hour
OH
(C99)寫入小時(shí)從24小時(shí)時(shí)鐘使用備選數(shù)字系統(tǒng),例如十八代替18的區(qū)域設(shè)置Ja_JP表示 tm_hour
I
寫入小時(shí)為十進(jìn)制數(shù),12個(gè)小時(shí)的時(shí)鐘(范圍[01,12]
) tm_hour
OI
(C99)使用替代數(shù)字系統(tǒng)從12小時(shí)時(shí)鐘寫入小時(shí),例如ja_JP語(yǔ)言環(huán)境中的六而不是06 tm_hour
M
寫入分鐘數(shù)(范圍[00,59]
) tm_min
OM
(C99)使用替代數(shù)字系統(tǒng)寫入分鐘,例如ja_JP語(yǔ)言環(huán)境中的二十五而不是25 tm_min
S
寫入第二個(gè)作為十進(jìn)制數(shù)(范圍[00,60]
) tm_sec
OS
(C99)使用替代數(shù)字系統(tǒng)寫第二個(gè),例如ja_JP語(yǔ)言環(huán)境中的二十四而不是24個(gè) tm_sec
其他 c
寫入標(biāo)準(zhǔn)日期和時(shí)間字符串,例如Sun Oct 17 04:41:13 2010
(取決于語(yǔ)言環(huán)境)全部 Ec
(C99)寫入備選日期和時(shí)間字符串,例如在ja_JP語(yǔ)言環(huán)境中使用平成23年(年平成23年)而不是2011年(2011年),全部 x
寫入本地化日期表示(與語(yǔ)言環(huán)境有關(guān))全部 Ex
(C99)在ja_JP語(yǔ)言環(huán)境中使用平成23年(年平23)而不是2011年(2011年)編寫替代日期表示法,全部 X
寫入本地時(shí)間表示(與語(yǔ)言環(huán)境有關(guān))全部 EX
(C99)全部寫入替代時(shí)間表示(區(qū)域依賴) D
(C99),相當(dāng)于“%米/%d /%Y” , ,tm_montm_mdaytm_year
F
(C99),相當(dāng)于“%Y-%間- %d” (在ISO 8601的日期格式) tm_mon
,tm_mday
,tm_year
r
(C99)寫入局部12小時(shí)制的時(shí)間(當(dāng)前位置有關(guān)) tm_hour
,tm_min
,tm_sec
R
(C99)相當(dāng)于“%H:%M” tm_hour
,tm_min
T
(C99),相當(dāng)于“%H:%M:%S” (在ISO 8601時(shí)間格式) tm_hour
,tm_min
,tm_sec
p
寫入局部上午或下午(當(dāng)前位置有關(guān)) tm_hour
z
(C99)將UTC的偏移量在ISO 8601格式(例如-0430
),或沒(méi)有字符,如果時(shí)區(qū)信息不可 tm_isdst
Z
寫入的時(shí)區(qū)名稱或縮寫,如果時(shí)區(qū)信息不可用,或者沒(méi)有文字(語(yǔ)言環(huán)境而定) tm_isdst
時(shí)間 - 指向指定格式化時(shí)間的struct tm對(duì)象的指針
寫入字符數(shù)組的字節(jié)數(shù)str
不包括終止'\0'
成功。如果count
在整個(gè)字符串可以存儲(chǔ)之前達(dá)到,0
則返回并且內(nèi)容未定義。
#include <stdio.h>#include <time.h>#include <locale.h> int main(void){ char buff[70]; struct tm my_time = { .tm_year=112, // = year 2012 .tm_mon=9, // = 10th month .tm_mday=9, // = 9th day .tm_hour=8, // = 8 hours .tm_min=10, // = 10 minutes .tm_sec=20 // = 20 secs }; if (strftime(buff, sizeof buff, "%A %c", &my_time)) { puts(buff); } else { puts("strftime failed"); } setlocale(LC_TIME, "el_GR.utf8"); if (strftime(buff, sizeof buff, "%A %c", &my_time)) { puts(buff); } else { puts("strftime failed"); }}
輸出:
Sunday Sun Oct 9 08:10:20 2012Κυριακ? Κυρ 09 Οκτ 2012 08:10:20 πμ EST
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.27.3.5 strftime函數(shù)(p:394-397)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.23.3.5 strftime函數(shù)(p:343-347)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.12.3.5 strftime函數(shù)