Help us understand the problem. What is going on with this article?

C++11 or later で epoch time から時刻の文字列を作るメモ

背景

epoch time などから, 時刻の文字列を作りたい.

なにやらいろいろ関数あってどれをつかえばいいかわからない.

C とかですと, strftime がよく使われているでしょうか?

https://en.cppreference.com/w/cpp/chrono/c/strftime

C++11 でナウな感じで文字列を作る

C++11 から, stream 用に std::put_time がつきました.

https://en.cppreference.com/w/cpp/io/manip/put_time

std::stringstream と組み合わせてあげましょう.

iomanip に定義されているので注意です!

速度が気になる?

locale が絡むと処理が非常にかかるという話も噂でききますので, 時差とかも少しおかしてもよくて単に year/month/day くらい表示したいのであれば, epoch 時刻から自前で計算する手もあるでしょう.

https://stackoverflow.com/questions/1692184/converting-epoch-time-to-real-date-time

文字列から時刻データに変換する.

https://en.cppreference.com/w/cpp/io/manip/get_time

get_time で行けるやも?

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした