std::chrono의 time_point 형의 변수값을 특정 포맷을 가진 문자열 String 변수로 변환이 필요할 때 다음 코드를 참고한다.
1 2 3 4 5 6 7 8 9 | std::string CMyDateTime::TimepointToString(const std::chrono::system_clock::time_point& p_tpTime, const std::string& p_sFormat) { auto converted_timep = std::chrono::system_clock::to_time_t(p_tpTime); std::ostringstream oss; oss << std::put_time(std::localtime(&converted_timep), p_sFormat.c_str()); return oss.str(); } |
위의 함수를 호출할 땐 다음과 같이 호출하면 된다.
1 2 | std::string sDate; sDate = TimepointToString(p_tpTime, "%Y%m%d%H%M%S"); |
'Language Proficiency > C++' 카테고리의 다른 글
Variable Sized Arrays (0) | 2018.07.31 |
---|---|
간단한 String 변수 다루기(Trim, 중복제거 등) (0) | 2018.07.27 |
날짜시간(YYYYMMDDHHMMSS) 문자열을 chrono의 time_point로 변환하기 (0) | 2018.07.27 |
std::thread의 thread_id를 문자 변환 (0) | 2018.07.27 |
std::sort 함수 (0) | 2018.07.27 |