当前位置:网站首页>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 for genome coordinate conversion
- PKG package manager usage instance in FreeBSD
- CentOS8之mysql基本用法
- 【云原生】2.5 Kubernetes 核心实战(下)
- 可升级合约的原理-DelegateCall
- A white hole formed by antineutrons produced by particle accelerators
- Mmrotate rotation target detection framework usage record
- Homer预测motif
- mmrotate旋转目标检测框架使用记录
- Win11 arm system configuration Net core environment variable
猜你喜欢
随机推荐
MySQL basic statement
Homer forecast motif
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
启牛商学院给的股票账户安全吗?能开户吗?
Is it safe to open a stock account through the QR code of the securities manager? Or is it safe to open an account in a securities company?
ros gazebo相关包的安装
Summary of data export methods in powerbi
Basic usage of MySQL in centos8
通过券商经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
SSRF
RPA进阶(二)Uipath应用实践
TIPC messaging3
The difference between SQL left join main table restrictions written after on and where
String (Analog
Homer预测motif
原生方法合并word
Some things configured from ros1 to ros2
A sharp tool for exposing data inconsistencies -- a real-time verification system
基于 Openzeppelin 的可升级合约解决方案的注意事项