How to round up the time to next hour?
-
This is the code:
@
startDate->setDateTime( QDateTime::currentDateTime() );
finishDate->setDateTime( QDateTime::currentDateTime() );
finishDate->setDateTime(startDate->dateTime().addSecs( 3600 ));
@For example the time now is 12:55
I need the start time to be rounded up to 13:00
Also the finish time to rounded up to 14:00Anyone have any ideas on how to do this?
-
You could use "QTime::setHMS":http://qt-project.org/doc/qt-5/qtime.html#setHMS and hardcode minutes to 0 (and add 1 to current hour if secs != 0).
-
@
QDateTime current = QDateTime::currentDateTime();
QTime time = current.time();if (time.minute() != 0) {
time.setHMS(time.hour() + 1, 0, 0, 0);
current.setTime(time);
}
@