0

I find no indication that there is a format for milliseconds in C. I save images more than once a second and need an additional index. My code now is:

time_t     now;
struct tm  ts;
time(&now);
ts = *localtime(&now);
strftime(buf, sizeof(buf), "%Y%m%d-%H%M%S", &ts);

Linux 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux GNU Make 4.1

  • See gettimeofday() and clock_gettime() – Stéphane Chazelas Mar 25 '18 at 18:10
  • Another potential solution (perhaps you thought of this but decided against it) is to simply append an additional digit on images that were saved at the same exact time (-1,-2,-3, etc). I think the end result would be more human-readable than simply milliseconds. – arcsin Mar 25 '18 at 18:14
  • +1 for @arcsin’s solution, especially since milliseconds are often not enough to distinguish different files... – Stephen Kitt Mar 25 '18 at 18:22
  • @arcsin’s so I do it at the moment, but the reset at the end of seconds is complicated, or is there a one-liner? – ThomasDr Mar 25 '18 at 19:13
  • @arcsin’s my frame reset code is if (buf[14] != bufold[14]) { frame = 0; size_t destination_size = sizeof (bufold); strncpy(bufold, buf, destination_size); } – ThomasDr Mar 25 '18 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.