1、c++或者QT开发中获取系统当前时间
QString timeStamp = QString("");
SYSTEMTIME sys;//获取系统时间
GetLocalTime(&sys);
QString yearStr = QString("%1").arg(sys.wYear, 4, 10, QLatin1Char('0'));
QString monthStr = QString("%1").arg(sys.wMonth, 2, 10, QLatin1Char('0'));
QString dayStr = QString("%1").arg(sys.wDay, 2, 10, QLatin1Char('0'));
QString hourStr = QString("%1").arg(sys.wHour, 2, 10, QLatin1Char('0'));
QString minuteStr = QString("%1").arg(sys.wMinute, 2, 10, QLatin1Char('0'));
QString secondStr = QString("%1").arg(sys.wSecond, 2, 10, QLatin1Char('0'));
QString milliSecondStr = QString("%1").arg(sys.wMilliseconds, 3, 10, QLatin1Char('0'));
timeStamp = yearStr + monthStr + dayStr + hourStr + minuteStr + secondStr + milliSecondStr;
qDebug() << "dateStr:" << timeStamp;
注意:
1、需要添加头文件:#include <wtypes.h>