Qt5中的QDateTime分类

本文展示使用Qt库中QDateTime类的不同日期时间格式化选项。通过实例代码演示了如何获取当前日期时间并将其格式化为多种标准格式,如ISO日期、本地日期等,并比较不同日期时间对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

    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();
}


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值