PDA

View Full Version : QTime to a format which I can use in a calculation



Gavin Harper
14th March 2011, 19:37
Hello,

I am putting QTime values in my SQLite database however, it represents a duration which I want to use as part of a calculation (Speed = Distance / Time).

What would be the best format to convert (and an example would be greatly appreciated, though not necessary) to convert the QTime into a data type suitable for the calculation.

I have been looking at the documentation though I am unsure of which methods to use and what would be best.

Thank you for any help or advice you can offer!

SixDegrees
14th March 2011, 20:12
QDateTime.toTime_t() returns the instant as the number of seconds since the Unix epoch began. Or, you can combine QDate.JulianDate() with QTime.msec() to form a floating point number that can be subtracted from a similar construct to yield a duration spanning any two arbitrary dates.

Gavin Harper
14th March 2011, 20:24
Thank you!

The thing is though, the time registered is a duration, for example 01:27:03 is 1 hour, 27 mins and 3 seconds.

I would like to convert this into something similar to the UNIX epoch time but the number of seconds passed since 00:00:00, in this case 5223.

unit
14th March 2011, 21:02
See QTime::secsTo

wysota
14th March 2011, 23:15
The obvious choice is to convert it to seconds or miliseconds. If you can't find the right method then just use your head and do the calculation manually, I'm sure you can calculate how many seconds makes one hour.