Reputation: 1136
I want to get the local time in real time.The code and result is as follow, it showed strange;
int main() {
while (true) {
char sentdata[64] = { 0 };
GetLocalTime(&sys);
sprintf(sentdata, "A,%02d:%02d:%02d.%03d,B\n", sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
cout << sentdata << endl;
}
return 0;
}
I tried same code on other PC, the result shown is as following, it can show every millisecond.
Why the tmie is same in some loop? I think the time should be different every loop.
Upvotes: 0
Views: 199
Reputation: 1528
This a typical timing behavior on Windows systems, even with the high-resolution clock: time only increases in jumps of about 16 ms.
For accurate timing on Windows, see this answer
Upvotes: 5
Reputation: 5359
Your code runs in nanoseconds, while the output is in milliseconds.
Upvotes: 1