0

I'd like to get the time:

  • In milliseconds (or better)
  • In millisecond resolution (or better)
  • Using a standard, cross platform method
  • As an unsigned integer

The actual meaning of the timestamp (aka, whether its time since epoch or the program's running time) is not at all important, as long as it can be used to calculate an accurate delta time.

I have tried <time.h> but have found it not to be very accurate and somebody recommended not using it in another answer.

<chrono> is recommended in other questions but it doesn't actually return the time as an integer, but rather some sort of strange object.

The code that I used in <chrono> is auto time = std::chrono::steady_clock::now().

In Java, this is simply System.currentTimeMillis().

Lucien
  • 776
  • 3
  • 12
  • 40

1 Answers1

1

You need to cast to the time duration you expect:

std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();

Have a look at the documentation.

unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62