PDA

View Full Version : Difference between two DateTime object



merry
10th February 2010, 11:15
Hi,
I am looking for a function which gives me the difference between two DateTime objects. in hour or minutes.
OR
Just give me the difference between them in seconds.

aamer4yu
10th February 2010, 11:35
QDateTime::daysTo

QDateTime::secsTo

merry
11th February 2010, 04:15
Actually i want to calculate the difference between current time and the UTC time ,
i use the following code for that.........
QDateTime firstDateTime = QDateTime::currentDateTime();
QDateTime lastDateTime = QDateTime::currentDateTime().toUTC();
QString o_r = firstDateTime.toString("yyyyMMddhhmmss");
QString p_r = lastDateTime.toString("yyyyMMddhhmmss");
seconds = firstDateTime.toTime_t() - lastDateTime.toTime_t();
// seconds = firstDateTime.secsTo(lastDateTime);



But seconds like this comes as 0 .Because both the times are converted to UTC before the calculation,and hence trhe result.
My concern how to find the difference between current time and UTC time.