QString QDate::toString ( const QString & format ) const
原文来自于QT Assistant,原文如下:
Returns the dateas a string. The format parameter determines the format of theresult string.
Theseexpressions may be used:
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 'Sunday'). Uses QDate::longDayName(). |
M |
the month as number without a leading zero (1 to 12) |
MM |
the month as number with a leading zero (01 to 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 to 99) |
yyyy |
the year as four digit number. If the year is negative, a minus sign is prepended in addition. |
All other inputcharacters will be ignored. Any sequence of characters that are enclosed insinglequotes will be treated as text and not be used as an expression. Twoconsecutive singlequotes ("''") are replaced by a singlequote in theoutput.
Example formatstrings (assuming that the QDate isthe 20 July 1969):
Format |
Result |
dd.MM.yyyy |
20.07.1969 |
ddd MMMM d yy |
Sun July 20 69 |
'The day is' dddd |
The day is Sunday |
If the datetimeis invalid, an empty string will be returned.
Warning: The Qt::ISODate format is only valid foryears in the range 0 to 9999. This restriction may apply to locale-awareformats as well, depending on the locale settings.
译文如下:
返回一个时间字符串,format 参数是定义了返回值的格式。
下面表格中这些表达式可以被用:
表达式 |
输出 |
d |
日期天中没有前缀0 (1 to 31) |
dd |
日期天中前缀有0 (01 to 31) |
ddd |
日期天的局部缩写 (如. 'Mon' to 'Sun'). Uses QDate::shortDayName(). |
dddd |
日期天全称 (如. 'Monday' to 'Sunday'). Uses QDate::longDayName(). |
M |
日期月中没有前缀0 (1 to 12) |
MM |
日期月中有前缀0(01 to 12) |
MMM |
日期月局部缩写 (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). |
MMMM |
日期月全称 (e.g. 'January' to 'December'). Uses QDate::longMonthName(). |
yy |
日期年的个位和十位,即有效位 (00 to 99) |
yyyy |
年日期4位有效数字. 如果年是负数,则预先在前面加上一个负号. |
例如格式字符串(假设QDATE是1969年7月20日):
Format |
Result |
dd.MM.yyyy |
20.07.1969 |
ddd MMMM d yy |
Sun July 20 69 |
'The day is' dddd |
The day is Sunday |
如果日期时间是无效的,一个空字符串将被返回。
值得注意的是:
Qt::ISODate格式仅适用于年为0~9999范围内,此限制可能适用于区域识别的格式为好,这取决于区域设置。