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#实现图片二值化例子(黑白效果)

    C#将图片2值化示例代码,原图及二值化后的图片如下: 原图: 二值化后的图像: 实现代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 ...

  2. 软件包管理:rpm命令管理-查询

    yum没有rpm查询的多. 使用包名时无所谓使用位置.因为查询是在后台数据库中查询的. 记忆是只需知道安装和升级时要加包全名,其余加包名.其实未安装的加包全名. rpm包可以手工指定安装路径,但不建议 ...

  3. Qt setMargin()和setSpacing() 的含义

    mainLayout=newQVBoxLayout(this); mainLayout->setMargin(30); //表示控件与窗体的左右边距 mainLayout->setSpac ...

  4. Summary: Deep Copy vs. Shallow Copy vs. Lazy Copy

    Object copy An object copy is an action in computing where a data object has its attributes copied t ...

  5. Q_UNUSED

    Q_UNUSED() 没有实质性的作用,用来避免编译器警告 void func( int a) { Q_UNUSED(a); //函数体内没有使用a,避免编译器警告 }

  6. Linux系统——LNMP分离式部署

    #### 安装nginx ```[root@localhost ~]# tar xf nginx-1.10.2.tar.gz -C /usr/src/[root@localhost ~]# cd /u ...

  7. SQLServer 重启服务后,自增1的标识列一次增长了1000(转自博问)

    sql2012:我重启了下sql服务,然后自增列Id居然一下子跳了100,怎么回事啊?(之前的数据Id为1,我重启服务后,第二条数据Id就变成1001了),我自增是1,求大神帮忙啊 SQLServer ...

  8. zw版【转发·台湾nvp系列Delphi例程】HALCON max_connection

    zw版[转发·台湾nvp系列Delphi例程]HALCON max_connection procedure TForm1.Button1Click(Sender: TObject);var ho_I ...

  9. 数据仓库基础(十)Informatica 组件1

    本文转载自:http://www.cnblogs.com/evencao/p/informatica.html Informatica主要的组件: Source Qualifier 从数据源读取数据 ...

  10. Linux基础命令---find

    file 判断指定文件的文件类型,它依据文件内容判断,并不依据扩展名.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法     ...