Time determination using QTime
-
Hi all.
I'm making an app that works only during the period.
Currently, the following code is used to determine if it is within the period.
However, this method does not work well when the end time (endH) exceeds 0:00.What can I do to solve it?
isIntime(int startH, int startM, endH, endM){ QTime startHM(startH, startM); QTime endHM(endH, endM); if(QTime::currentTime() >= startHMm && QTime::currentTime() < endHM){ return true; } else{ return false; } }
Thank you.
-
Hi all.
I'm making an app that works only during the period.
Currently, the following code is used to determine if it is within the period.
However, this method does not work well when the end time (endH) exceeds 0:00.What can I do to solve it?
isIntime(int startH, int startM, endH, endM){ QTime startHM(startH, startM); QTime endHM(endH, endM); if(QTime::currentTime() >= startHMm && QTime::currentTime() < endHM){ return true; } else{ return false; } }
Thank you.
-
Thank you, everyone.
I think it was probably solved with the following code.
Tonight I will see the result at 0: 5.isIntime(int startH, int startM,int endH, int endM){ QTime startHM(startH, startM); QTime endHM(endH, endM); QDate today = QDate::currentDate(); QDateTime startDHM(today, startHM); if(endHM < startHM){ today = today.addDays(1); } QDateTime eDHM(today, endHM); if(QDateTime::currentDateTime() >= startDHM && QDateTime::currentDateTime() < endDHM){ return true; } else{ return false; } }
-
Thank you, everyone.
I think it was probably solved with the following code.
Tonight I will see the result at 0: 5.isIntime(int startH, int startM,int endH, int endM){ QTime startHM(startH, startM); QTime endHM(endH, endM); QDate today = QDate::currentDate(); QDateTime startDHM(today, startHM); if(endHM < startHM){ today = today.addDays(1); } QDateTime eDHM(today, endHM); if(QDateTime::currentDateTime() >= startDHM && QDateTime::currentDateTime() < endDHM){ return true; } else{ return false; } }
@taku-s Oh, I apologize, I have read too fast your post and misunderstand your request!
isIntime(int startH, int startM,int endH, int endM){ QTime startHM(startH, startM); QTime endHM(endH, endM); QTime currHM(QTime::currentTime()); if(startHM <= endHM) return ((currHM >= startHM) && (currHM < endHM)); return ((currHM >= startHM) || (currHM < endHM)); }