博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QT获取系统时间,以及设置日期格式
阅读量:5793 次
发布时间:2019-06-18

本文共 2287 字,大约阅读时间需要 7 分钟。

hot3.png

 QDateTime time = QDateTime::currentDateTime();
    QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd");
    qDebug() << str;

例如我要在一个label上设置当前时间

QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间

QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式

label->setText(str);//在标签上显示时间

QString QDateTime::toString ( const QString & format ) const

Returns the datetime as a string. The format parameter determines the format of the result string.

These expressions may be used for the date:

Expression Output

d the day as number without a leading zero (1 to 31)

dd the day as number with a leading zero (01 to 31)

ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName().

dddd the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). Uses QDate::longDayName().

M the month as number without a leading zero (1-12)

MM the month as number with a leading zero (01-12)

MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().

MMMM the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName().

yy the year as two digit number (00-99)

yyyy the year as four digit number

These expressions may be used for the time:

Expression Output

h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)

hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)

m the minute without a leading zero (0 to 59)

mm the minute with a leading zero (00 to 59)

s the second without a leading zero (0 to 59)

ss the second with a leading zero (00 to 59)

z the milliseconds without leading zeroes (0 to 999)

zzz the milliseconds with leading zeroes (000 to 999)

AP use AM/PM display. AP will be replaced by either "AM" or "PM".

ap use am/pm display. ap will be replaced by either "am" or "pm".

All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output.

Example format strings (assumed that the QDateTime is 21 May 2001 14:13:09):

Format Result

dd.MM.yyyy 21.05.2001

ddd MMMM d yy Tue May 21 01

hh:mm:ss.zzz 14:13:09.042

h:m:s ap 2:13:9 pm

转载于:https://my.oschina.net/floristgao/blog/290579

你可能感兴趣的文章
一些kindle资源
查看>>
java springcloud版b2b2c社交电商spring cloud分布式微服务(十五)Springboot整合RabbitMQ...
查看>>
SpringCloud使用Prometheus监控(基于Eureka)
查看>>
10g手动创建数据库
查看>>
Linux—文件系统
查看>>
运用Loadrunner测试Mysql数据库性能
查看>>
Spring MVC EL表达式不能显示
查看>>
【致青春】我们挥霍时间的年代
查看>>
Windwos Server 2008 R2 DHCP服务
查看>>
SAS和SATA硬盘的区别
查看>>
现代程序设计 学生情况调查
查看>>
U盘安装linux后无法引导
查看>>
C# 矩阵作业
查看>>
俺的新书《Sencha Touch实战》终于出版了
查看>>
关于数据库查询时报“query block has incorrect number of result columns”
查看>>
li下的ul----多级列表
查看>>
UVa 11292 勇者斗恶龙(The Dragon of Loowater)
查看>>
线程退出时执行函数,处理资源
查看>>
java中关于时间的格式化
查看>>
Wine QQ2012 笔记
查看>>