如何使用標準庫在C++中將字符串轉換爲日期和時間對象?如何將字符串轉換爲C++中的日期?
這裏是我的字符串
string input_time = "071215"; //071215 represents 7th December 2015
的需求input_time
要轉換爲Date對象,這樣我可以與Date對象進行比較。
bool dateExpired = (input_time < now);
//where now is current date time
if(dateExpired) printf("Expired");
else printf("Not expired");
由於字符串的每個部分都是固定的(我猜),所以很容易提取相關數據並將其放入可用於獲取'time_t'的'struct tm'中。 – 2012-01-02 09:19:05
語言環境也很重要。我住在哪裏意味着2007年12月15日。 – 2012-01-02 09:21:34
您是否堅持使用該格式,或者您可以使用標準格式,例如http://en.wikipedia.org/wiki/ISO_8601? – juanchopanza 2012-01-02 09:23:41