std::put_time

std::put_time (날짜·시간 삽입 조작자)

캘린더 시간 tmb의 날짜·시간 정보를 형식 문자열 fmt에 따라 문자 문자열로 변환해 출력하는 조작자예요. C++11부터 있어요.

출처: cppreference

본문

<iomanip> 헤더에 정의돼 있어요.

template< class CharT >
/*unspecified*/ put_time( const std::tm* tmb, const CharT* fmt );

out << put_time(tmb, fmt) 표현식에서, CharT에 따라 std::strftime, std::wcsftime 등처럼, 출력 스트림 out에 현재 적용된 로케일의 std::time_put 패싯을 따라 주어진 캘린더 시간 tmb의 날짜·시간 정보를 형식 문자열 fmt에 따라 문자 문자열로 변환해요.

매개변수

  • tmbstd::localtime 또는 std::gmtime에서 얻은 캘린더 시간 구조체에 대한 포인터.
  • fmt — 변환 형식을 지정하는 null로 끝나는 CharT 문자열에 대한 포인터.

반환값

out << put_time(tmb, fmt)out을 돌려주는 미지정 타입 객체.

예제

#include <iostream>
#include <iomanip>
#include <ctime>

int main()
{
    std::time_t t = std::time(nullptr);
    std::tm* tm = std::localtime(&t);
    std::cout << std::put_time(tm, "%Y-%m-%d") << '\n'; // 예: "2024-03-15"
}

더 알아보기 (Learn more)

cppreference