http://blog.csdn.net/zzk197/article/details/7498593

例如我要在一个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

【转】QT获取系统时间,以及设置日期格式的更多相关文章

  1. QT 获取系统时间

    1.导入QTime #include <QTime> 2.定义QTime 对象接受当前时间 QTime t=QTime::currentTime(); t就是系统时间. 3.将t转化为st ...

  2. js获取此刻时间或者把日期格式时间转换成字符串格式的时间

    getTime(val){ if (val&val instanceof Date){ d = val; }else{ d = new Date(); }; var year = d.getF ...

  3. C# 获取系统时间及时间格式

    --DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 取当前年月日时分秒      currentTime=System. ...

  4. c++ 怎样获取系统时间

    c++ 怎样获取系统时间 2008-04-28 15:34 //方案— 长处:仅使用C标准库:缺点:仅仅能精确到秒级 #include <time.h> #include <stdi ...

  5. Java 如何获取系统时间

    Java 如何获取系统时间 import java.text.SimpleDateFormat; import java.util.Date; public class Test { public s ...

  6. Android获取系统时间的多种方法

    Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...

  7. 按照相应的格式获取系统时间并将其转化为SQL中匹配的(date)时间格式

    在获取时间时需要对时间格式进行设置,此时就需要用到SimpleDateFormat 类 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM ...

  8. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

  9. 用PHP获取系统时间时,时间比当前时间少8个小时

    自PHP5.0开始,用PHP获取系统时间时,时间比当前时间少8个小时.原因是PHP.ini中没有设置timezone时,PHP是使用的UTC时间,所以在中国时间要少8小时. 解决办法: 1.在PHP. ...

随机推荐

  1. c语言的字符串拷贝函数的精简

    #include <stdio.h>#include <string.h>void str_cpy(char * to, char *from){    while ((*to ...

  2. 借root之名,行流氓之实,劝告,root需谨慎

    20160425++++++ 今日再回头看这篇文章,貌似有点偏激了一点,不过xda论坛上有个疑似kingroot开发团队的用户说明了kingroot确实对supersu做了限制,说是supersu在替 ...

  3. 查看Tensorflow版本

    python -c 'import tensorflow as tf; print(tf.__version__)' # for Python 2 python3 -c 'import tensorf ...

  4. fiddler——一款莱斯的抓包工具

    进行页面和接口调试时候,好使得抓包工具还是有作用得,如postman,fiddler,相比,postman更适合用来接口调试和与其他人一起联调,而抓包监控web得时候我更喜欢用fiddler: 当然, ...

  5. 中国程序化购买广告解析:RTB/DSP/Ad Exchange/SSP/DMP,思维导图

    中国程序化购买广告解析:RTB/DSP/Ad Exchange/SSP/DMP 概念 程序化购买( Programmatic Buying):通过数字化.自动化.系统化的方式改造广告主.代理公司.媒体 ...

  6. python3.4学习笔记(七) 学习网站博客推荐

    python3.4学习笔记(七) 学习网站博客推荐 深入 Python 3http://sebug.net/paper/books/dive-into-python3/<深入 Python 3& ...

  7. 编译错误 error C2451: “std::_Unforced”类型的条件表达式是非法的

    part 1 编译器 vs2015 VC++. 完整的错误信息粘贴如下: d:\program files (x86)\microsoft visual studio 14.0\vc\include\ ...

  8. 20145307陈俊达_安卓逆向分析_dex2jar&jd-gui的使用

    20145307陈俊达_安卓逆向分析_dex2jar&jd-gui的使用 引言 这次免考选择了四个项目,难度也是从简到难,最开始先写一个工具的使用 想要开发安卓首先要会编写代码,但是想要逆向分 ...

  9. 面向对象第一话,大战java正则表达式

    本周我们迎来第一项任务,java面向对象之实现对一串字符的匹配以及构造出计算的多项式,最终得出计算的结果.简而言之,可以用以下的要求来看题目: 输入的多项式字符串中不得出现非法字符 多项式的输入型式, ...

  10. [c/c++]指针(2)

    首先呢,讲讲数组 数组就是一连串的地址对不对?所以它们的地址是紧挨着的 1 | 2 | 3 | 4 | 2 | 0 1 2 3 4 那我们把一个数组的首地址赋给一个指针变量 ] = {, , , , ...