I try to read seconds after 1970 to a QDateTime. I.e.: startT = 1.390309552938E9
Therefor I use:
QDateTime time = QDateTime::fromMSecsSinceEpoch(startT*1000); // *1000 because a have seconds while qt expecting milliseconds
now I want to compare this to another time I get with QDateTime::toString:
QDate startDate = QDate::fromString(datestr, "yyyyMMdd");
QTime time = QTime::fromString(timestr, "hhmmss");
QDateTime datetime = QDateTime(date, time, Qt::UTC);
datestr and timestr look for example like this: '20140121' and '130358'
I want to compare if time
and datetime
are equal (to the seconds, so excepts of milliseconds) therefore I use something like this:
if (time < datetime)
but it doesn't work?! Can someone help me here?
Thank you!
edit:
I do:
QDateTime time = QDateTime::fromMSecsSinceEpoch(startT*1000);
then I give this Information (time) back with:
void Data::setTime(const QDateTime& obTime)
{
time = QDateTime(obTime);
}
where obTime is my times
later in the code I return my value by:
QDateTime time = newData.getTime();
any getTime is:
QDateTime MetObs::getTime() const
{
return time;
}
The retrieval of datetime is the same as mentioned above. There is no complication with the two definitions of "time" because it is at another position of the Programm
And than I try to use:
if (time < datetime)
Another Information:
when I print out the values as Strings with:
QString timestring = time.toString(Qt::ISODate);
QString datetimestring = datetime.toString(Qt::ISODate);
cout << timestring.toAscii().data() << endl;
cout << datetimestring.toAscii().data() << endl;
this comes out:
2014-01-21T13:03:59
2014-01-21T13:03:58Z