English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
funzione della libreria C size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) secondo format definiti nella struttura di formattazione, la struttura di formattazione timeptr tempo rappresentato, e viene memorizzato in str definiti.
Di seguito è riportata la dichiarazione della funzione strftime().
size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)
indicatore | rappresenta | Esempio |
---|---|---|
%a | 缩写的星期几名称 | Sun |
%A | 完整的星期几名称 | Sunday |
%b | 缩写的月份名称 | Mar |
%B | 完整的月份名称 | March |
%c | 日期和时间表示法 | Sun Aug 19 02:56:02 2012 |
%d | 一月中的第几天(01-31) | 19 |
%H | 24 小时格式的小时(00-23) | 14 |
%I | 12 小时格式的小时(01-12) | 05 |
%j | 一年中的第几天(001-366) | 231 |
%m | 十进制数表示的月份(01-12) | 08 |
%M | 分(00-59) | 55 |
%p | AM o PM | PM |
%S | 秒(00-61) | 02 |
%U | 一年中的第几周,以第一个星期日作为第一周的第一天(00-53) | 33 |
%w | 十进制数表示的星期几,星期日表示为 0(0-6) | 4 |
%W | 一年中的第几周,以第一个星期一作为第一周的第一天(00-53) | 34 |
%x | 日期表示法 | 08/19/12 |
%X | 时间表示法 | Rappresentazione del tempo |
02:50:06 | %y | Anno, gli ultimi due numeri (00-99) |
01 | %Y | Anno |
2012 | %Z | Il nome o l'abbreviazione della fascia oraria |
CDT | Un simbolo %% | % |
struct tm { int tm_sec; /* Secondo,intervallo da 0 a 59 */ int tm_min; /* Minuto,intervallo da 0 a 59 */ int tm_hour; /* Ora,intervallo da 0 a 23 */ int tm_mday; /* Giorno del mese,intervallo da 1 a 31 */ int tm_mon; /* Mese,intervallo da 0 a 11 */ int tm_year; /* Anno dal 1900 */ int tm_wday; /* Giorno della settimana,intervallo da 0 a 6 */ int tm_yday; /* Giorno dell'anno,intervallo da 0 a 365 */ int tm_isdst; /* Orario estivo */ };
Se la stringa C generata è più corta di size caratteri (compreso il carattere di terminazione di stringa), viene restituito il numero di caratteri copiati in str (escluso il carattere di terminazione di stringa), altrimenti viene restituito zero.
Il seguente esempio dimostra l'uso della funzione strftime().
#include <stdio.h> #include <time.h> int main () { time_t rawtime; struct tm *info; char buffer[80]; time( &rawtime ); info = localtime( &rawtime ); strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", info); printf("格式化的日期 & 时间 : |%s|\n", buffer ); return(0); {}
让我们编译并运行上面的程序,这将产生以下结果:
格式化的日期 & 时间 : |2018-09-19 08:59:07|