Qt 返回系统时间

来源:互联网 发布:黎明杀机优化补丁 编辑:程序博客网 时间:2024/05/04 09:25

uint QDateTime::toTime_t () const

Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC).

On systems that do not support time zones, this function will behave as if local time were Qt::UTC.

See also setTime_t().


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:

ExpressionOutputdthe day as number without a leading zero (1 to 31)ddthe day as number with a leading zero (01 to 31)dddthe abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName().ddddthe long localized day name (e.g. 'Monday' to 'Qt::Sunday'). Uses QDate::longDayName().Mthe month as number without a leading zero (1-12)MMthe month as number with a leading zero (01-12)MMMthe abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().MMMMthe long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName().yythe year as two digit number (00-99)yyyythe year as four digit number

These expressions may be used for the time:

ExpressionOutpuththe hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)hhthe hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)mthe minute without a leading zero (0 to 59)mmthe minute with a leading zero (00 to 59)sthe second without a leading zero (0 to 59)ssthe second with a leading zero (00 to 59)zthe milliseconds without leading zeroes (0 to 999)zzzthe milliseconds with leading zeroes (000 to 999)APuse AM/PM display. AP will be replaced by either "AM" or "PM".apuse 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):

FormatResultdd.MM.yyyy21.05.2001ddd MMMM d yyTue May 21 01hh:mm:ss.zzz14:13:09.042h:m:s ap2:13:9 pm

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

See also QDate::toString() and QTime::toString().


The toString method of the QDataTime can accept a formatstring.   Example:
        QDateTime sometime = QDateTime::currentDateTime();
QString outString = someTime.toString("yyyy MM dd hh:mm:ss");This will produce a string like:2006 Nov 20 15:20:03

原创粉丝点击