【转】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. ...
随机推荐
- 如何减少block的嵌套层次?
1.首先了解一个概念 函数式反应型编程(FRP) —— 实时互动应用开发的新思路 http://www.infoq.com/cn/articles/functional-reactive-progra ...
- thinkphp 隐藏表单验证原理
function savetoken() //创建session('hash') ,然后在魔板中表单中加入隐藏域 getsession('hash'),提交表单验证值是否一样,如果一样验证通过,同时重 ...
- VS中代码对齐等快捷键
在VS2008中,选定代码后,按Ctrl+K+F组合键,可以自动进行代码对齐. 注意:要先按下Ctrl和K,再按下F,因为Ctrl+F是查找的快捷键. 也可以先按下Ctrl+K,再按下Ctrl+F. ...
- mvc actionresult返回各种文件
public ActionResult ReviewFile(string folderName, string fileBasename, string extendName) { //以后根据后缀 ...
- Trove系列(二)—Trove 的架构和流程介绍
Trove主要逻辑目前Trove支持用户创建一个数据库服务实例,在实例里可以创建多个数据库并进行管理.数据库服务实例目前通过Nova API来创建,然后同样通过Nova API创建一个Volume(未 ...
- MySQL从删库到跑路(四)——MySQL数据库创建实例
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.创建数据库 1.创建数据库 创建数据库,指定数据库的默认字符集为utf8.create database sch ...
- UVA10298 Power Strings
UVA10298 Power Strings hash+乘法逆元+一点点数学知识 我们用取余法算出主串的hash,然后从小到大枚举子串的长度 显然,如果若干个子串的复制的hash值之和等于主串的has ...
- AMS1117稳压模块
AMS1117有降压稳压的作用.我们使用的是AMS1117-5,输出5V电压. 理论参数: 输出条件 最小值 理论值 最大值 理论电路图: 引脚图:
- 常用maven命令总结
常用Maven命令: mvn -v //查看版本 mvn archetype:create //创建 Maven 项目 mvn compile //编译源代码 mvn test-compile //编 ...
- 递增三元组|2018年蓝桥杯B组题解析第六题-fishers
标题:递增三元组 给定三个整数数组 A = [A1, A2, ... AN], B = [B1, B2, ... BN], C = [C1, C2, ... CN], 请你统计有多少个三元组(i, j ...