-1

I am writing a code in c and I need to add milliseconds to the current time So far, i have :

current_time = time(NULL); loc_time=localtime(&current_time);

however this only gives HH:MM:SS when I need HH:MM:SS:MM

Say the local time is 20:00:00:10. I want to adding 10 milliseconds and display it so it displays 20:00:00:20. I am fairly new to c so any help is much appreciated. I am confused as time is of type int format and, to add milli seconds I will have to add .001 seconds to the current second which is not an int.

James Mark
  • 141
  • 2
  • 3
  • 6

1 Answers1

3

The problem is that "localtime()" API only has granularity of seconds (not milliseconds).

Try gettimeofday()

See also:

If you're on Windows, you can also try QueryPerformanceCounter():

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190