当前位置:网站首页>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;
}
边栏推荐
- II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
- MySQL basic statement
- Approximate sum count (approximate
- ASTParser 解析含有emum 枚举方法的类文件的踩坑记
- sqlite 修改列类型
- Order by injection
- mysql 基本语句
- 制造业数字化转型和精益生产什么关系
- Resources reads 2D texture and converts it to PNG format
- Tdsql | difficult employment? Tencent cloud database micro authentication to help you
猜你喜欢
可升级合约的原理-DelegateCall
从攻击面视角,看信创零信任方案实践
揭露数据不一致的利器 —— 实时核对系统
RPA进阶(二)Uipath应用实践
Pit of the start attribute of enumrate
解决uniapp列表快速滑动页面数据空白问题
Verilog 和VHDL有符号数和无符号数相关运算
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
RPA advanced (II) uipath application practice
Always report errors when connecting to MySQL database
随机推荐
Develop scalable contracts based on hardhat and openzeppelin (II)
MySql存储过程游标遍历结果集
Wechat applet uses Baidu API to achieve plant recognition
Gaode draws lines according to the track
Importerror: impossible d'importer le nom « graph» de « graphviz»
Approximate sum count (approximate
C#多维数组的属性获取方法及操作注意
Summary of flutter problems
Principe du contrat évolutif - delegatecall
Introduction to interface debugging tools
mysql 基本语句
Functional interfaces and method references
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
A white hole formed by antineutrons produced by particle accelerators
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
MySQL比较运算符IN问题求解
PLC-Recorder快速监控多个PLC位的技巧
Verilog and VHDL signed and unsigned number correlation operations
Installation of ROS gazebo related packages
【云原生】2.5 Kubernetes 核心实战(下)