Siddiqui
Siddiqui

Reputation: 7840

UTC timestamp in millisecond using C++ under Windows

How do I get the UTC time in milliseconds under the Windows platform?

I am using the standard library which give me UTC time in seconds. I want to get the time in milliseconds. Is there a reference of another library which give me the accurate UTC time in milliseconds?

Upvotes: 3

Views: 6213

Answers (2)

Hans Passant
Hans Passant

Reputation: 941257

GetSystemTime() produces a UTC time stamp with millisecond resolution. Accuracy however is far worse, the clock usually updates at 15.625 millisecond intervals on most Windows machines. There isn't much point in chasing improved accuracy, any clock that provides an absolute time stamp is subject to drift. You'd need dedicated hardware, usually a GPS radio clock, to get something better. Which are hard to use properly on a non-realtime multi-tasking operating system. Worst-case latency can be as much as 200 milliseconds.

Upvotes: 6

avakar
avakar

Reputation: 32635

Use GetSystemTime API function, or perhaps GetSystemTimeAsFileTime if you want a single number.

Upvotes: 7

Related Questions