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

QDateTime类的QString toString ( const QString & format ) const 函数用于格式化时间输入非常好。
例如:QDateTime::currentDateTime().toString("yyyy年MM月dd日 hh:mm:ss"); //输出为“2011年10月15日 18:22:13”
具体的格式设置Qt的文档中写得比较全:

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

If the datetime is invalid, an empty string will be returned.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值