QTime start(10, 0, 0); // start time QTime end(11, 30, 0); // end time qint64 duration = start.msecsTo(end); // calculate duration // duration is now 5400000 (milliseconds)
QTime now = QTime::currentTime(); // get current time QTime deadline(15, 0, 0); // a deadline time qint64 remaining = now.msecsTo(deadline); // calculate remaining time // remaining is now the number of milliseconds until the deadlineIn this example, we retrieved the current time using the static currentTime method of the QTime class. We then created another QTime instance representing a deadline time. Finally, we calculated the remaining time until the deadline using the msecsTo method and assigned the result to a qint64 variable. Package library: Qt Core library.