PDA

View Full Version : time in microseconds



stevocz
4th November 2016, 10:34
Hi.
How can i get current time in microseconds but from 1.january.0001. something as .NET MinValue

i found only this solution.
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count()+62135596800000000) ;

Killian
4th November 2016, 10:59
Well, that's not really a Qt-related question, is it? ;-)

Most timers are not really accurate down to microseconds. For using chrono I recommend reading this: http://www.informit.com/articles/article.aspx?p=1881386&seqNum=2
You could also have a look at QueryPerformanceFrequency and QueryPerformanceCounter which I find to be more easy-to-use (but at the cost of platform dependency).

stevocz
4th November 2016, 12:02
is not really Qt. but i must run this app on SLES 11 SP3 with QT4.6 and there missing chrono. I need find different solution.

Camryn64
4th November 2016, 13:45
interesting.. want to know the answer :)

anda_skoa
4th November 2016, 14:46
If you were looking for milliseconds, that would be easy with QDateTime::msecsTo().

Cheers,
_

stevocz
5th November 2016, 18:41
QDateTime::msecsTo() is not awailable in QT4.6, only QTime::msecsTo().

anda_skoa
6th November 2016, 13:59
You could do the same as the Qt5 implementation does;
https://code.woboq.org/qt5/qtbase/src/corelib/tools/qdatetime.cpp.html#_ZNK9QDateTime7msecsToERKS_

Cheers,
_

stevocz
7th November 2016, 08:38
but there is in milliseconds not microseconds

anda_skoa
7th November 2016, 09:37
but there is in milliseconds not microseconds

How could I have missed that?
Oh, wait, I didn't.



If you were looking for milliseconds


Though you could just multiply by 1000, as Killian already pointed out it is unlikely that the system has microseconds precision at all.

Cheers,
_

stevocz
7th November 2016, 09:40
sorry. my mistake