////// 获取保存文件的路径 /// ///string GetFileSavePathName() { SYSTEMTIME st = { 0 }; GetLocalTime(&st); //获取当前时间 可精确到ms int year = st.wYear; int month = st.wMonth; int day = st.wDay; int hour = st.wHour; int minute = st.wMinute; int second = st.wSecond; int milliSec = st.wMilliseconds; char yearStr[5], monthStr[3], dayStr[3], hourStr[3], minuteStr[3], secondStr[3], milliSecStr[6]; sprintf(yearStr, "%d", year); sprintf(monthStr, "%d", month); sprintf(dayStr, "%d", day); sprintf(hourStr, "%d", hour); sprintf(minuteStr, "%d", minute); sprintf(secondStr, "%d", second); sprintf(milliSecStr, "%d", milliSec); if (minuteStr[1] == '') { minuteStr[2] = ''; minuteStr[1] = minuteStr[0]; minuteStr[0] = '0'; } sprintf(secondStr, "%d", second); // 秒。 if (secondStr[1] == '') // 如果秒为一位,如5,则需要转换字符串为两位,如05。 { secondStr[2] = ''; secondStr[1] = secondStr[0]; secondStr[0] = '0'; } char dir[20]; sprintf(dir, "%s-%s-%s-%s-%s", yearStr, monthStr, dayStr, hourStr, minuteStr); string strDir(dir); CString strDirName; strDirName.Format("%s\FileSave\", g_szPath); if (GetFileAttributes(strDirName) == -1) { CreateDirectory(strDirName, NULL); } strDirName.Format("%s\FileSave\%s", g_szPath, dir); if (GetFileAttributes(strDirName) == -1) { CreateDirectory(strDirName, NULL); } char file[256]; // 定义总日期时间char*变量。 sprintf(file, "%s\%s_%s_%s_%s.dat", strDirName, hourStr, minuteStr, secondStr, milliSecStr);// 将年月日时分秒合并。 return string(file); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)