我知道這可能很簡單,但是我怀疑使用C ++会很簡單.如何將01/01/2008形式的字元串轉換為日期,以便可以操作它? 我很高兴將字元串分解為日,年,年的組成部分.如果解決方案仅是windows,也很高兴。
最新回復
- 5月前1 #
- 5月前2 #
我不使用
strptime
就能弄清楚將日期细分為各个部分,即日,月,年,然後:
struct tm tm; time_t rawtime; time ( &rawtime ); tm = *localtime ( &rawtime ); tm.tm_year = year - 1900; tm.tm_mon = month - 1; tm.tm_mday = day; mktime(&tm);
tm
現在可以轉換成time_t
- 5月前3 #
您可以尝試Boost.Date_Time輸入/輸出。
- 5月前4 #
對於每个正在尋找
strptime()
的人 對於windows,它需要功能源本身才能起作用.不幸的是,最新的NetBSD代碼無法轻松移植到windows。我本人已使用 here實現 (strptime.h和strptime.c)。
可以找到另一有用的代碼段 here .這最初来自Google Codesearch,現在已经不存在了。
希望這可以节省很多搜尋,因為我花了相当长的時間才找到它(並且最经常出現在這个問题上)。
- 5月前5 #
POCO庫具有DateTimeParser類,這可能会有所帮助 你這樣。 http://www.appinf.com/docs/poco/Poco.DateTimeParser.html
相似問題
- C ++ string ::發現複雜性c++stringalgorithmsubstringtimecomplexity2021-01-11 07:57
- c++:在针對C ++ 03時,將std :: basic_string <t>用作连續緩衝區是否合理?c++stringwinapistlc++032021-01-11 06:27
- c++:从函式返迴" const char *"是一个好主意吗?c++string2021-01-10 22:57
- c++:从" const char *"到" char"的無效轉換c++stringcompilererrors2021-01-10 18:56