当前位置:网站首页>【QT】Qt获取前几天/后几天的时间
【QT】Qt获取前几天/后几天的时间
2022-07-29 17:26:00 【Cappuccino-jay】
Qt修改获取的时间
QDateTime currentTime = QDateTime::currentDateTime(); //获取当前系统时间
QString current_Time = currentTime.toString("yyyy/MM/dd hh:mm"); //设置时间格式
QString beforeDayTime = currentTime.addDays(-1).toString("yyyy/MM/dd hh:mm"); //获取前一天时间
QString beforeDayTime = currentTime.addDays(+4).toString("yyyy/MM/dd hh:mm");//将-1更改为+4,获得的时间为当前时间四天后的时间
ui窗口获取:
ui->dateTimeStart->setDateTime(currentTime.addDays(-1)); //获取前一天时间
ui->dateTimeEnd->setDateTime(currentTime); //获取当前时间
其他:
You can increment (or decrement) a datetime by a given number of milliseconds using addMSecs(), seconds using addSecs(), or days using addDays(). Similarly, you can use addMonths() and addYears()
QDateTime monthAgo = currentTime.addMonths(-1); //获取前一月的时间
QDateTime yearAgo = currentTime.addYears(-1); //获取前一年的时间
备注:参数为负数就是获取以前的时间,正数就是获取未来的时间。
边栏推荐
- "Record" MMDetection Introduction
- 多线程并发Callable
- 利用 JMeter 压测上传和下载接口实战
- Internet Explorer 结束了它 26 年作为顶级浏览器的历史角色
- Web APIs DOM- 网页特效篇 综合案例
- Dialogue with Academician Yu Fei of the Canadian Academy of Engineering: Looking for "Shannon's Theorem" in the field of AI
- 手动SET返回PageInfo对象
- 休息天的早晨感觉不到在休息
- Blender 源码分析(2)
- 赠书|《软硬件融合》带你学习从CPU、DSP到软硬件融合的计算创新之路
猜你喜欢

Arduino框架下轻量级ssd1306 I2C屏幕驱动库

母公司冲刺IPO卡壳,驾考宝典遇多地驾校“抵制”风波

【考研英语词汇训练营】Day 16 —— bankrupt,remain,regulate,construct,reflect

Out of breath!After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...

机器学习:知道模型评估中的SSE、“肘”部法、SC系数和CH系数的实现原理

【STM32CubeMX】STM32H743配置IAP升级

mysql存储过程 实现全量同步数据并自动创建表

解决 @RefreshScope 导致定时任务注解 @Scheduled 失效

Which is better, traditional render farm or cloud render farm?

不同的 DAO 对世界带来的改变
随机推荐
【深度学习】使用yolov5对数据进行预标注
脉冲风采|Committer 专访——腾讯工程师张大伟喊你吃“螃蟹”啦
[High Concurrency] I used multithreading to further optimize the massive data proofreading system under the billion-level traffic e-commerce business, and the performance has been improved by 200% aga
Six basic experiments of STC8h1k28
【码蹄集新手村600题】求空间直角坐标系中俩点之间的距离
一文搞定代码中的命名
免费创建一个令人惊叹的网站的7个技巧
One's deceased father grind English vocabulary training camp Day 】 16 - bankrupt, remain, regulate, the construct and reflect
[Deep Learning] Use yolov5 to pre-label data
利用 JMeter 压测上传和下载接口实战
学会 arthas,让你 3 年经验掌握 5 年功力!
要卖课、要带货,知识付费系统帮你一步搞定!
11.99万起,东风风行游艇上市,产品力越级诚意满满
机器学习:知道模型评估中的SSE、“肘”部法、SC系数和CH系数的实现原理
阿里最新发布的《Alibaba分布式系统速成笔记》PDF版,供下载
InstallAnywhere 2022
数学分析_证明_两个重要极限(同济版本)
赠书|《软硬件融合》带你学习从CPU、DSP到软硬件融合的计算创新之路
hihoCoder#: 博弈游戏·Nim游戏
Out of breath!After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...