当前位置:网站首页>【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); //获取前一年的时间
备注:参数为负数就是获取以前的时间,正数就是获取未来的时间。
边栏推荐
- hihoCoder#1037 : 数字三角形(DP)
- js骏马奔腾点击裁剪js特效
- Internet Explorer 结束了它 26 年作为顶级浏览器的历史角色
- js图片等分对比插件
- This week's investment report: CeFi accumulates venture capital attraction
- 利用 JMeter 压测上传和下载接口实战
- TweenMax+SVG火箭升空动画js特效
- 直播实录 | 37 手游如何用 StarRocks 实现用户画像分析
- NFTScan and PANews jointly release multi-chain NFT data analysis report
- Learn to arthas, 3 years experience with 5 years work force you!
猜你喜欢
随机推荐
js骏马奔腾点击裁剪js特效
「硬核」labelme 图片中显示标签
Pagination with LIMIT
4G无线模块 电力通信模块
分批数据遍历的优化
字典树(Trie)
学会 arthas,让你 3 年经验掌握 5 年功力!
NFTScan 与 PANews 联合发布多链 NFT 数据分析报告
地球超2亿蛋白质结构全预测,AlphaFold引爆「蛋白质全宇宙」
泰山OFFICE技术讲座:影响文字效果的因素,由四大升级为五大
Blender 源码解析(1)
[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
译文推荐 | 调试 BookKeeper 协议 - 无界 Ledger
[memory] grandma's song
气数已尽!运营 23 年,昔日“国内第一大电商网站”黄了。。。
Dialogue with Academician Yu Fei of the Canadian Academy of Engineering: Looking for "Shannon's Theorem" in the field of AI
A redis tool class to solve cache breakdown, cache penetration
xatlas源码解析(七)
P4769 [NOI2018] 冒泡排序(组合数学)
TweenMax+SVG火箭升空动画js特效









