strftime
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| ヘッダ <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以上) | |
書式文字列 format に従って日付および時刻の情報を指定されたカレンダー時刻 time からヌル終端マルチバイト文字列 str に変換します。 最大 count バイトが書き込まれます。
引数
| str | - | 出力用文字配列の最初の要素を指すポインタ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| count | - | 書き込む最大文字数 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| format | - | 変換の書式を指定するヌル終端マルチバイト文字列を指すポインタ。
書式文字列はゼロ個以上の変換指定子と (
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time | - | 変換する時刻を表す構造体 tm のオブジェクトを指すポインタ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
戻り値
成功した場合は、 str の指す文字配列に書き込まれた、終端の '\0' を含まないバイト数。 文字列全体を格納する前に count に達した場合は、 0 が返され、内容は未定義になります。
例
Run this code
#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 standard (ISO/IEC 9899:2011):
- 7.27.3.5 The strftime function (p: 394-397)
- C99 standard (ISO/IEC 9899:1999):
- 7.23.3.5 The strftime function (p: 343-347)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.12.3.5 The strftime function
関連項目
(C11) |
tm オブジェクトをテキスト表現に変換します (関数) |
(C11) |
time_t オブジェクトをテキスト表現に変換します (関数) |
(C95) |
tm オブジェクトをカスタムテキスト表現のワイド文字列に変換します (関数) |
strftime の C++リファレンス
| |