WriteLog("TextDate : "+QDateTime::currentDateTime().toString(Qt::TextDate));
WriteLog("ISODate : "+QDateTime::currentDateTime().toString(Qt::ISODate));
WriteLog("ISODateWithMs : "+QDateTime::currentDateTime().toString(Qt::ISODateWithMs));
WriteLog("SystemLocaleShortDate : "+QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate));
WriteLog("SystemLocaleLongDate : "+QDateTime::currentDateTime().toString(Qt::SystemLocaleLongDate));
WriteLog("DefaultLocaleShortDate : "+QDateTime::currentDateTime().toString(Qt::DefaultLocaleShortDate));
WriteLog("DefaultLocaleLongDate : "+QDateTime::currentDateTime().toString(Qt::DefaultLocaleLongDate));
WriteLog("SystemLocaleDate : "+QDateTime::currentDateTime().toString(Qt::SystemLocaleDate));
WriteLog("LocaleDate : "+QDateTime::currentDateTime().toString(Qt::LocaleDate));
WriteLog("LocalDate : "+QDateTime::currentDateTime().toString(Qt::LocalDate));
WriteLog("RFC2822Date : "+QDateTime::currentDateTime().toString(Qt::RFC2822Date));
结果如下:
TextDate : 周二 8月 15 14:35:40 2017
ISODate : 2017-08-15T14:35:40
ISODateWithMs : 2017-08-15T14:35:40.507
SystemLocaleShortDate : 2017/8/15 14:35
SystemLocaleLongDate : 2017年8月15日 14:35:40
DefaultLocaleShortDate : 2017/8/15 14:35
DefaultLocaleLongDate : 2017年8月15日 14:35:40
SystemLocaleDate : 2017/8/15 14:35
LocaleDate : 2017/8/15 14:35
LocalDate : 2017/8/15 14:35
RFC2822Date : 15 Aug 2017 14:35:40 +0800
#include <QCoreApplication>
#include <QDateTime>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QDateTime dt1=QDateTime::fromString("2017/8/15 14:35",Qt::LocalDate);
QDateTime dt2=QDateTime::fromString("2017/8/16 14:35",Qt::LocalDate);
QDateTime dt3=QDateTime::fromString("2017/8/17 14:35",Qt::LocalDate);
cout<<"dt2>dt1 ? ="<<(dt2>dt1)<<endl;
cout<<"dt3<dt2 ? ="<<(dt3<dt2)<<endl;
cout<<dt2.secsTo(dt1)<<endl;
return a.exec();
}