C-standard-library-c-function-strftime
提供:Dev Guides
Cライブラリ関数-strftime()
説明
Cライブラリ関数 size_t strftime(char str、size_t maxsize、const char format、const struct tm timeptr)は、 *format で定義され、格納されているフォーマット規則に従って、構造体 timeptr で表される時間をフォーマットします。 str 。
宣言
strftime()関数の宣言は次のとおりです。
パラメーター
- str -これは、結果のC文字列がコピーされる宛先配列へのポインタです。
- maxsize -これはstrにコピーされる文字の最大数です。
- format -これは、通常の文字と特殊な形式指定子の任意の組み合わせを含むC文字列です。 これらの書式指定子は、tmで指定された時間を表すために、対応する値の関数に置き換えられます。 フォーマット指定子は-
Specifier | Replaced By | Example |
---|---|---|
%a | Abbreviated weekday name | Sun |
%A | Full weekday name | Sunday |
%b | Abbreviated month name | Mar |
%B | Full month name | March |
%c | Date and time representation | Sun Aug 19 02:56:02 2012 |
%d | Day of the month (01-31) | 19 |
%H | Hour in 24h format (00-23) | 14 |
%I | Hour in 12h format (01-12) | 05 |
%j | Day of the year (001-366) | 231 |
%m | Month as a decimal number (01-12) | 08 |
%M | Minute (00-59) | 55 |
%p | AM or PM designation | PM |
%S | Second (00-61) | 02 |
%U | Week number with the first Sunday as the first day of week one (00-53) | 33 |
%w | Weekday as a decimal number with Sunday as 0 (0-6) | 4 |
%W | Week number with the first Monday as the first day of week one (00-53) | 34 |
%x | Date representation | 08/19/12 |
%X | Time representation | 02:50:06 |
%y | Year, last two digits (00-99) | 01 |
%Y | Year | 2012 |
%Z | Timezone name or abbreviation | CDT |
%% | A % sign | % |
- timeptr -これは、以下に示すようにコンポーネントに分割されたカレンダー時間を含むtm構造体へのポインタです-
戻り値
結果のC文字列がsize未満の文字(終端のnull文字を含む)に収まる場合、strにコピーされた文字の総数(終端のnull文字を含まない)が返されます。そうでない場合は、ゼロを返します。
例
次の例は、strftime()関数の使用法を示しています。
次の結果を生成する上記のプログラムをコンパイルして実行しましょう-