我知道这可能很简单但是C++我怀疑它会是.如何将01/01/2008形式的字符串转换为日期,以便我可以操作它?我很高兴能把这个字符串分成日月成分.如果解决方案仅限Windows,也很高兴.
ken*_*nny 16
#include <time.h>
char *strptime(const char *buf, const char *format, struct tm *tm);
Run Code Online (Sandbox Code Playgroud)
我没有使用它想出来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);
Run Code Online (Sandbox Code Playgroud)
tm现在可以转换为a time_t并进行操作.