获取当前系统时间作为文件名

在录制视频开始时候,我们需要获取当前时间,作为文件名,以方便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);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值