QT获取系统时间,以及设置日期格式
2013-08-14 09:22
686 查看
例如我要在一个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:
These expressions may be used for the time:
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):
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 |
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". |
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 |
相关文章推荐
- QT获取系统时间,以及设置日期格式
- QT获取系统时间以及设置日期格式
- QT获取系统时间,以及设置日期格式
- 【转】QT获取系统时间,以及设置日期格式
- JAVA,jsp,oracle获取系统当前时间以及日期格式转换!
- 【转载】Delphi获取与设置系统时间格式(长日期与短日期)
- iOS 获取系统时间以及时间与日期格式互相转换
- QT系列:获取系统时间 日期时间格式
- QT修改、获取系统时间,以及设置日…
- android 日期格式处理 ,获取当前系统时间并设置格式为--年--月--日
- qt4 设置系统日期 时间,set time date, set system date time
- Java 以指定日期时间格式获取当前时间、以及每隔一秒刷新一次的方法------附带实例
- Android TextClock获取系统时间,格式跟随设置改变
- Android:获取当前系统时间生成日期格式
- 系统日期时间格式设置
- Qt中DateTimeEdit等时间日期控件设置显示格式
- android 日期时间格式转换;软键盘显示消失;获取系统title
- qt4 设置系统日期 时间,set time date, set system date time
- iOS中获取当前时间和日期并设置格式
- 设置系统日期时间格式