当前位置:网站首页>What week is a date obtained by QT
What week is a date obtained by QT
2022-07-02 11:43:00 【zjl_ yujizhong】
Because the function test of the previous version appeared and 1 month 1 The same day as Monday (1-7), There will be a small week , Such as 2022 year 1 month 8 The number is identified as the first week .
The new method is changed into the following :
ceil((start.daysTo(value) - count) /7.0) + 1;
Less than two people make up 0 Handle , Make sure the return value is in four digit week format .
QString class::getWeek(QDateTime value)
{
int result = -1;
QDateTime start = QDateTime::fromString(value.toString("yyyy") + "0101", "yyyyMMdd");
int myWeek = start.date().dayOfWeek();
int count = 7 - myWeek; // If the difference exceeds this value, it will be the next week
double num = start.daysTo(value);
result = ceil((start.daysTo(value) - count) /7.0) + 1;
QString str = "";
if(result < 10)
str = "0" + QString::number(result);
else
str = result;
str = value.toString("yy") + str;
return str;
}
--------------------------------------------------------- Old version split line ---------------------------------------------------------
be based on QT Of QDateTime、QDate Function to get the day of the week and date interval ( Leap years are calculated by QT Call library adjustment return )
Get the function of the week :
// Calculate the incoming time as the week of the year
int class::getWeek(QDateTime value)
{
int result = -1; // Return results
// Get the first day of the year , Used to determine the number of days in the first week
QDateTime start = QDateTime::fromString(value.toString("yyyy") + "0101", "yyyyMMdd");
int myWeek = start.date().dayOfWeek(); // dayOfWeek To get the day of the week (1~7)
int count = 7 - myWeek; // The first week includes count+1 God
// daysTo Is the number of days from the call date to the parameter date ( If the parameter date is earlier than the call date, a negative number is returned )
double num = start.daysTo(value)/7.0;
result = ceil(num); // ceil Is the rounding up function
// Because the first week is mostly dissatisfied 7 God , Therefore, the next week needs to determine the number of days in the first week ( Remainder )
if((start.daysTo(value) % 7) - count > 0)
++result;
return result;
}
边栏推荐
- liftOver进行基因组坐标转换
- 2022年遭“挤爆”的三款透明LED显示屏
- String (Analog
- 念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
- C#多维数组的属性获取方法及操作注意
- II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
- ctf 记录
- A sharp tool for exposing data inconsistencies -- a real-time verification system
- Internship report skywalking distributed link tracking?
- Eight sorting summaries
猜你喜欢
CTF record
Redis超出最大内存错误OOM command not allowed when used memory &gt; 'maxmemory'
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
tqdm的多行显示与单行显示
2022年4月17日五心红娘团队收获双份喜报
亚马逊云科技 Community Builder 申请窗口开启
2022年遭“挤爆”的三款透明LED显示屏
tidb-dm报警DM_sync_process_exists_with_error排查
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
随机推荐
The difference between SQL left join main table restrictions written after on and where
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
String (Analog
预言机链上链下调研
Bedtools tutorial
C#基于当前时间,获取唯一识别号(ID)的方法
mysql链表数据存储查询排序问题
从ros1到ros2配置的一些东西
抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
Win11 arm system configuration Net core environment variable
基于Hardhat和Openzeppelin开发可升级合约(一)
PKG package manager usage instance in FreeBSD
Precautions for scalable contract solution based on openzeppelin
Skills of PLC recorder in quickly monitoring multiple PLC bits
Internship report skywalking distributed link tracking?
Mmrotate rotation target detection framework usage record
Rest (XOR) position and thinking
Wechat applet uses Baidu API to achieve plant recognition
Homer forecast motif
Jenkins installation