求C++保存文件以系统时间命名的方法

2025-04-15 17:00:34
推荐回答(1个)
回答1:

在StartSave之前要确定保存的文件名,文件名中要包含时间:

	CTime currTime;
currTime = CTime::GetCurrentTime();
CString strTime;
strTime.Format(_T("%.4d-%.2d-%.2d-%.2d-%.2d-%.2d"), currTime.GetYear(), currTime.GetMonth(), currTime.GetDay(), currTime.GetHour(), currTime.GetMinute(), currTime.GetSecond());

以上的代码中,strTime中会记录当前的时间格式为“年年年年-月月-日日-时时-分分-秒秒”

需要把这段字符添加到文件名中去:

	CString strPath;
strPath = _T("d:\\nbumooc\\raw_") + strTime +_T(".ts");

StartSave("10.1.58.84", strPath);

 简单来说,用上面的两段代码替换一下StartSave();