libbb: introduce and use strftime_[YYYYMMDD]HHMMSS()
[oweals/busybox.git] / procps / watch.c
index 36af1cca7ccdb878f1f8eefcbe71b78a227fe3fe..0397f21bf2b01a77509920d609188ff85f4e8efb 100644 (file)
@@ -69,7 +69,6 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
                printf("\033[H""\033[J");
                if (!(opt & 0x2)) { // no -t
                        const unsigned time_len = sizeof("1234-67-90 23:56:89");
-                       time_t t;
 
                        // STDERR_FILENO is procps3 compat:
                        // "watch ls 2>/dev/null" does not detect tty size
@@ -79,10 +78,13 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
                                free(header);
                                header = xasprintf("Every %us: %-*s", period, (int)width, cmd);
                        }
-                       time(&t);
-                       if (time_len < width)
-                               strftime(header + width - time_len, time_len,
-                                       "%Y-%m-%d %H:%M:%S", localtime(&t));
+                       if (time_len < width) {
+                               strftime_YYYYMMDDHHMMSS(
+                                       header + width - time_len,
+                                       time_len,
+                                       /*time_t*:*/ NULL
+                               );
+                       }
 
                        // compat: empty line between header and cmd output
                        printf("%s\n\n", header);