【转】QT获取系统时间,以及设置日期格式
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获取系统时间,以及设置日期格式的更多相关文章
- QT 获取系统时间
1.导入QTime #include <QTime> 2.定义QTime 对象接受当前时间 QTime t=QTime::currentTime(); t就是系统时间. 3.将t转化为st ...
- js获取此刻时间或者把日期格式时间转换成字符串格式的时间
getTime(val){ if (val&val instanceof Date){ d = val; }else{ d = new Date(); }; var year = d.getF ...
- C# 获取系统时间及时间格式
--DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 取当前年月日时分秒 currentTime=System. ...
- c++ 怎样获取系统时间
c++ 怎样获取系统时间 2008-04-28 15:34 //方案— 长处:仅使用C标准库:缺点:仅仅能精确到秒级 #include <time.h> #include <stdi ...
- Java 如何获取系统时间
Java 如何获取系统时间 import java.text.SimpleDateFormat; import java.util.Date; public class Test { public s ...
- Android获取系统时间的多种方法
Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...
- 按照相应的格式获取系统时间并将其转化为SQL中匹配的(date)时间格式
在获取时间时需要对时间格式进行设置,此时就需要用到SimpleDateFormat 类 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM ...
- Android获取系统时间方法的总结
Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...
- 用PHP获取系统时间时,时间比当前时间少8个小时
自PHP5.0开始,用PHP获取系统时间时,时间比当前时间少8个小时.原因是PHP.ini中没有设置timezone时,PHP是使用的UTC时间,所以在中国时间要少8小时. 解决办法: 1.在PHP. ...
随机推荐
- win10 + cuda(v9.0) 安装TensorFlow-gpu版
之前在实习公司的电脑上装过TensorFlow-gpu,那时候很快就装好了.但在自己的笔记本上装时,却搞了很久... 一部分原因是因为用校园网下载cuda toolkit 和cudnn ,总是在最后时 ...
- testNG入门详解
TestNG 的注释: @DataProvider @ExpectedExceptions @Factory @Test @Parameters <suite name="Parame ...
- Qt 布局管理器
在一个颜值当道的今天,无论买衣服,买车还是追星,颜值的高低已经变成了大家最看重的(不管男性女性都一样,千万别和我说你不是):而对于程序猿来说,开发一款软件,不再只注重逻辑和稳定性,美观和用户友好性也是 ...
- Mysql查询一个表的所有字段名
select COLUMN_NAME from information_schema.`COLUMNS` -- 这行不变,照抄 where TABLE_SCHEMA = 'xerp' ...
- JSTL—标签
什么是JSTL标签? Jsp标准标签库(JSP Standerd Tag Library) JSTL的优点是什么? 1) 提供一组标准的标签 2)可用于编写动态功能 使用JSTL的步骤? 1)引入ja ...
- n的二进制中有几个1
实例十七:n的二进制中有几个1 方法:result=n & (n-1) n&(n-1)的目的使最低位的1不断翻转. 比如:n=108,其二进制表示为0110 1100,则n& ...
- uva11354 LCA+最小生成树+dp
源自大白书 题意 有n座城市通过m条双向道路相连,每条道路都有一个危险系数.你的任务是回答若干个询问,每个询问包含一个起点s和一个终点t,要求找到一条从s到t的路,使得途径所有的边的大最大危险系数最小 ...
- MySQL从删库到跑路_高级(一)——数据完整性
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.数据完整性简介 1.数据完整性简介 数据冗余是指数据库中存在一些重复的数据,数据完整性是指数据库中的数据能够正确 ...
- JSON自动生成相关类
开源项目地址:https://jsonclassgenerator.codeplex.com/SourceControl/latest 太好用了,这个
- 持续集成之二:搭建SVN服务器--Apache HTTP Server安装
安装环境 Red Hat Enterprise Linux Server release 7.3 (Maipo) jdk1.7.0_80 httpd-2.4.35.tar.gz apr-1.6.5.t ...