LoginSignup
1
1

More than 5 years have passed since last update.

[C++] 時間を日本語で出力する

Last updated at Posted at 2016-04-19

普通strftimeを使いましたら

time_t current;
time(&current);
struct tm* current_tm = localtime(&current);
char buf[256];
strftime(buf, 255, "%c", current_tm);
cout << buf << endl;

こうな感じになります

Tue Apr 19 11:47:16 2016

曜日はTueになります。

もしロケールを設定したら。

setlocale( LC_TIME, "ja_JP" );
time_t current;
time(&current);
struct tm* current_tm = localtime(&current);
char buf[256];
strftime(buf, 255, "%c", current_tm);
cout << buf << endl;

結果:

火  4/19 11:50:14 2016

曜日はになります。

他のフォーマットに関して、ここで参考できます。

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1