【转】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. ...
随机推荐
- python接口自动化 -参数关联(一)
原文地址https://www.cnblogs.com/yoyoketang/p/6886610.html 原文地址https://www.cnblogs.com/yoyoketang/ 原文地址ht ...
- Android下基于线程池的网络访问基础框架
引言 现在的Android开发很多都使用Volley.OkHttp.Retrofit等框架,这些框架固然有优秀的地方(以后会写代码学习分享),但是我们今天介绍一种基于Java线程池的网络访问框架. 实 ...
- 4:7 Struts实现Ajax
不使用插件: 返回数据: 使用插件: Action里面直接给User赋值,然后在前台拿值. type="json":表示返回json对象: root:表示作为跟对象 include ...
- 通俗理解RxJS(一)
自学 Rx 快有一个周了, 它非常适合处理复杂的异步场景.结合自己所学,决定写系列教程. 我认为, Rx 中强大的地方在于两处 管道思想,通过管道,我们订阅了数据的来源,并在数据源更新时响应 . 强大 ...
- 浅谈css中渐变衔接
无论transition还是keyframes,如何让变化更自然,这是前端应该考虑的问题. 这里,我简单总结下自己的方法. 以实践为例子. 1.图像渐变 @keyframes looppic{ fro ...
- ZOJ 3949 Edge to the Root
题意: 在一棵树中,可以从根节点往其他节点加一条边,使得根节点到其他所有节点的距离和最小,输出最小的距离和. 思路: 我们考虑在加的一条边为$1 \to v$,那么在树上从$1 \to v$的路径上, ...
- EntityFramework包含作用
System.Data.Entity.Infrastructure.DbQuery的引用需要加入上面那个包
- Python中type的用法
目录 描述 语法 用法 type和isinstance Type和Object 描述 python的 type 函数有两个用法,当只有一个参数的时候,返回对象的类型.当有三个参数的时候返回一个类对象. ...
- 浅谈为什么一个java源文件中只能有一个public类?
声明,本篇文章为转载 转载 http://blog.csdn.net/bareheadzzq/article/details/6562211 最近在一个java文件中实现了几个类,其中一个声明为pub ...
- 干货:Java并发编程系列之volatile(二)
接上一篇<Java并发编程系列之synchronized(一)>,这是第二篇,说的是关于并发编程的volatile元素. Java语言规范第三版中对volatile的定义如下:Java编程 ...