1

I need precise time stamp in my C program. Right now I'm using:

system("date +%H:%M:%S:%N");

which prints current time like:

09:29:26:616205874

Now I want to make this without the system(); call. I tried to use time.h library but it goes only to seconds precision. How do I make time stamp, formated same as above?

Ok, based on comments I'll edit a little bit: I'm using debian based linux and the precision doesn't have to be necessary in nanoseconds, milisecond will suffice. I just asked about nanoseconds because that is what I use right now with the system(); call

muliku
  • 416
  • 3
  • 17
  • 1
    Why you need this? How many nanoseconds will cost the time format, output or write in log file? Even microseconds cannot be guaranteed. – i486 Feb 19 '19 at 09:55
  • 2
    You have not specified your platform. On windows for getting nanosecond, you need special hardware. Have a look on this [question](https://stackoverflow.com/questions/1825720/c-high-precision-time-measurement-in-windows). However, on POSIX you can checkout this [question](https://stackoverflow.com/questions/275004/timer-function-to-provide-time-in-nano-seconds-using-c). You can also check [this library](https://github.com/jbenet/nanotime), if it is helpful. – MS_ Feb 19 '19 at 09:56
  • 2
    C doesn't have any high precision time facilities. You need to use your platform APIs for that. – n. m. could be an AI Feb 19 '19 at 09:58

0 Answers0