[Interest] QDateTime and std::chrono

Jérôme Godbout godboutj at amotus.ca
Fri Nov 2 16:40:49 CET 2018


Hi,
Maybe you can pass by a string, this would be highly inefficient but could be simple enough. I guess you should make the time into UTC too. You could use QString to std::string for the string stream. And do the following:

std::tm tm = {};
std::stringstream ss("Jan 9 2014 12:35:34"); // Change this for the QDateTime toString().toStdString()
ss >> std::get_time(&tm, "%b %d %Y %H:%M:%S");
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm)); 

I don't think it's the best solution, but could work easily if performance is not an issue. Hope someone have a better plan...

Jerome

-----Original Message-----
From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> On Behalf Of Roger Leigh
Sent: November 2, 2018 6:20 AM
To: interestqt-project.org <interest at qt-project.org>
Subject: [Interest] QDateTime and std::chrono

Hi folks,

Is there any recommended way to convert a QDateTime to a std::chrono::timepoint?  I'd like to take the value of
QFileInfo::lastModified() and pass it to an interface using e.g. 
std::chrono<high_resolution_clock, milliseconds> (or nanoseconds).

However, making this work portably, including all the epoch and leap second issues, looks complicated and error-prone.  Has anyone got any suggestions for how best to do this?


Thanks,
Roger
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list