当前位置:网站首页>【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); //获取前一年的时间
备注:参数为负数就是获取以前的时间,正数就是获取未来的时间。
边栏推荐
- The structure of the earth's over 200 million proteins is fully predicted, and AlphaFold detonates the "protein universe"
- 解决 @RefreshScope 导致定时任务注解 @Scheduled 失效
- 剑指offer专项突击版第14天
- lua-调试技巧
- 华东师范大学副校长周傲英:数据赋能,从数据库到数据中台
- Analyst: Baidu could become China's most valuable company by 2030
- 本周投融报:CeFi积聚风投吸引力
- 【深度学习】YOLO转VOC VOC转YOLO
- Dialogue with Academician Yu Fei of the Canadian Academy of Engineering: Looking for "Shannon's Theorem" in the field of AI
- 多线程并发Callable
猜你喜欢
银行有没有必要建立数据中台?看完你就明白了
Xatlas source code parsing (7)
Network Effects in Web3
NFTScan and PANews jointly release multi-chain NFT data analysis report
管理层换血,魏建军求变,长城能告别“命悬一线”吗?
Analyst: Baidu could become China's most valuable company by 2030
leetcode94 -- 二叉树的中序遍历
详解析构函数、拷贝构造函数
巴比特 | 元宇宙每日必读:连续七个季度出现亏损,Meta元宇宙部门Q2亏损28 亿美元,扎克伯格称这种情况可能会持续数年...
NFTScan 与 PANews 联合发布多链 NFT 数据分析报告
随机推荐
Out of breath!After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
一文搞定代码中的命名
华东师范大学副校长周傲英:数据赋能,从数据库到数据中台
一文了解信创背景下 SAN 存储转型路线
[网络]IPv6基础IPv6概述
One's deceased father grind English vocabulary training camp Day 17 】 -- espresso, ultimate, gradually, detect, dimension
【WSL】wsl pip NewConnectionError
解决报错Unsupported field: HourOfDay
“我“眼中的测试/开发程序员,预想与现实的碰撞......
leetcode141 -- 环形链表
大佬们一个 sql 优化问题。我有个4千万的表。然后加了一个字段,只有10+条数据会给值,其他行数据
kubernetes之资源限制及QOS服务质量
【Mysql系列】01_查询+排序
Domino服务器SSL证书安装指南
Blender 源码解析(1)
[Code Hoof Set Novice Village 600 Questions] Detailed explanation of pow() function
【STM32CubeMX】STM32H743配置IAP升级
2022开放原子全球开源峰会OpenAnolis分论坛圆满落幕
MySQL数据库基础
service事物失效如何获取代理事物