Search code examples
c++qtqtime

Getting milliseconds accuracy current time in Qt


Qt documentation about QTime::currentTime() says :

Note that the accuracy depends on the accuracy of the underlying operating system; not all systems provide 1-millisecond accuracy.

But is there any way to get this time with milliseconds accuracy in windows 7?


Solution

  • You can use QDateTime class and convert the current time with the appropriate format:

    QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss,zzz")
    

    where 'z' corresponds to miliseconds accuracy.