当前位置:网站首页>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;
}边栏推荐
猜你喜欢

A white hole formed by antineutrons produced by particle accelerators

八大排序汇总

mmrotate旋转目标检测框架使用记录

ctf 记录

Skills of PLC recorder in quickly monitoring multiple PLC bits

可昇級合約的原理-DelegateCall

excel表格中选中单元格出现十字带阴影的选中效果

What is the relationship between digital transformation of manufacturing industry and lean production

JS -- take a number randomly from the array every call, and it cannot be the same as the last time

Verilog and VHDL signed and unsigned number correlation operations
随机推荐
RPA进阶(二)Uipath应用实践
RPA advanced (II) uipath application practice
Jenkins installation
Develop scalable contracts based on hardhat and openzeppelin (II)
亚马逊云科技 Community Builder 申请窗口开启
enumrate的start属性的坑
TDSQL|就业难?腾讯云数据库微认证来帮你
Cluster Analysis in R Simplified and Enhanced
Jinshanyun - 2023 Summer Internship
Tick Data and Resampling
tqdm的多行显示与单行显示
从ros1到ros2配置的一些东西
Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
Pit of the start attribute of enumrate
Is it safe to open a stock account online? I'm a novice, please guide me
What is the relationship between digital transformation of manufacturing industry and lean production
Webauthn - official development document
Bedtools tutorial
C#多维数组的属性获取方法及操作注意
TIPC Service and Topology Tracking4