문자열의 날짜시간 포맷(YYYYMMDDHHmmSS)을 std::chrono의 time_point로 변환해서 계산해야 하는 경우, 다음과 같이 변환 함수를 만들 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | std::chrono::system_clock::time_point CMyDateTime::convertStrToTimepoint(const std::string& p_sDate) { //int tm_sec; /* seconds after the minute - [0,59] */ //int tm_min; /* minutes after the hour - [0,59] */ //int tm_hour; /* hours since midnight - [0,23] */ //int tm_mday; /* day of the month - [1,31] */ //int tm_mon; /* months since January - [0,11] */ //int tm_year; /* years since 1900 */ //int tm_wday; /* days since Sunday - [0,6] */ //int tm_yday; /* days since January 1 - [0,365] */ //int tm_isdst; /* daylight savings time flag */ // p_sDate 파라미터는 년월일시분초로 전달됨(YYYYMMDDHHMMSS) std::tm date = {}; date.tm_year = std::stoi(p_sDate.substr(0, 4)) - 1900; date.tm_mon = std::stoi(p_sDate.substr(4, 2)) - 1; date.tm_mday = std::stoi(p_sDate.substr(6, 2)); date.tm_hour = std::stoi(p_sDate.substr(8, 2)); date.tm_min = std::stoi(p_sDate.substr(10, 2)); date.tm_sec = std::stoi(p_sDate.substr(12, 2)); return std::chrono::system_clock::from_time_t(std::mktime(&date)); } |
'Language Proficiency > C++' 카테고리의 다른 글
Variable Sized Arrays (0) | 2018.07.31 |
---|---|
간단한 String 변수 다루기(Trim, 중복제거 등) (0) | 2018.07.27 |
std::chrono의 time_point를 문자열로 변환하기 (0) | 2018.07.27 |
std::thread의 thread_id를 문자 변환 (0) | 2018.07.27 |
std::sort 함수 (0) | 2018.07.27 |