[Qt-interest] How calculate time span (days, hours, minutes) QDateTime difference?

Ed Sutton ESutton at fescorp.com
Fri Jun 11 17:58:08 CEST 2010


>http://doc.trolltech.com/4.6/qdatetime.html#secsTo

>gives you seconds.

>The rest is trivial.

Thank you Dan and Jason.

QDateTime::secsTo() does the trick with some additional work.

I was hoping I had missed the Qt equivalent of the .NET TimeSpan structure.

http://msdn.microsoft.com/en-us/library/system.timespan.aspx


DateTime departure = new DateTime(2010, 6, 12, 18, 32, 0);
DateTime arrival = new DateTime(2010, 6, 13, 22, 47, 0);
TimeSpan travelTime = arrival - departure;
Console.WriteLine("{0} - {1} = {2}", arrival, departure, travelTime);
// The example displays the following output:
//       6/13/2010 10:47:00 PM - 6/12/2010 6:32:00 PM = 1.04:15:00


Thanks again,

-Ed



“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

----- Ed Sutton <ESutton at fescorp.com<mailto:ESutton at fescorp.com>> wrote:
What is the Qt way to calculate the elapsed date time between two QDateTime values?

My goal is to display the difference in days, hours, and minutes.

Thanks in advance,

-Ed


_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com<mailto:Qt-interest at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-interest


_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com<mailto:Qt-interest at trolltech.com>
http://lists.trolltech.com/mailman/listinfo/qt-interest


-Ed





More information about the Qt-interest-old mailing list