当前位置:网站首页>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;
}边栏推荐
- Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
- 2022年4月17日五心红娘团队收获双份喜报
- Bedtools tutorial
- tqdm的多行显示与单行显示
- C file and folder operation
- Introduction to interface debugging tools
- 基于Hardhat编写合约测试用例
- 揭露数据不一致的利器 —— 实时核对系统
- 抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
- 高德根据轨迹画线
猜你喜欢

Multi line display and single line display of tqdm

【IDEA】使用插件一键逆向生成代码

Solve the problem of data blank in the quick sliding page of the uniapp list

Tick Data and Resampling

GGPlot Examples Best Reference

enumrate的start属性的坑

MTK full dump grab

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

八大排序汇总

Principe du contrat évolutif - delegatecall
随机推荐
RPA advanced (II) uipath application practice
由粒子加速器产生的反中子形成的白洞
基于 Openzeppelin 的可升级合约解决方案的注意事项
Resources reads 2D texture and converts it to PNG format
Is bond fund safe? Does the bond buying foundation lose principal?
ROS lacks catkin_ pkg
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
webauthn——官方开发文档
函数式接口和方法引用
php 根据经纬度查询距离
GGPlot Examples Best Reference
enumrate的start属性的坑
Xiao Sha's pain (double pointer
spritejs
JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
Some suggestions for young people who are about to enter the workplace in the graduation season
Map set assignment to database
Internship report skywalking distributed link tracking?
Tdsql | difficult employment? Tencent cloud database micro authentication to help you
Some things configured from ros1 to ros2