Important: Please read the Qt Code of Conduct -

Time stamp with microsecond resolution

  • Hi all,
    I need to get the elapsed Time from the epoch in microsecond. I see is present a function qint64 QDateTime::currentMSecsSinceEpoch () that returns the time in millisecond. Is present a similar function that returns the time in microseconds?


  • qint64 QElapsedTimer::nsecsElapsed () const

    How precise the output is depends on the platform, though.

    PS: Not exactly what you asked for, but the closest thing I found.

  • Ok Thanks,

    I have already seen this function but returns the number of nanoseconds from the start of QTimer.
    I need the number of microsecond form the epoch that in the function QDateTime::currentMSecsSinceEpoch () is 1/01/1970 ( in my case could be set to another date)..

  • If it's not really important what the start time is (as long as it's some fixed point in time), you could start a QElapsedTimer at application start, and measure the nsecs from there. But I do not know your use case, so I can't really advise.

Log in to reply