在录制视频开始时候,我们需要获取当前时间,作为文件名,以方便FTP扫描文件,决定是否上传。
windows系统VS2013平台下通过,代码实现如下:
#include <assert.h>
#include <atlstr.h>
#include <atltime.h>
#include <locale.h>
//获取当前时间作为文件名
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());
CString strPath;
strPath = _T("D:\\client\\Debug\\") + strTime + _T(".h264");
//将CString转换成const char *
setlocale(LC_ALL, "chs");
char sz[128] = { 0 };
wcstombs(sz, strPath, 127);
const char *sPath = sz;
在windows10QT4.8中,实现代码如下:
#include "QString"
#include "QDateTime"
QString str_time;
QDateTime time = QDateTime::currentDateTime();
str_time = time.toString("yyyy-MM-dd_hh-mm-ss");
const char *temp =str_time.toAscii().data();
printf("%s\n",temp);