Browse Source

date: Add "-u" argument for printing current Unix timestamp.

Andreas Kling 6 years ago
parent
commit
3ae75e04ec
1 changed files with 9 additions and 5 deletions
  1. 9 5
      Userland/date.cpp

+ 9 - 5
Userland/date.cpp

@@ -1,12 +1,16 @@
-#include <LibC/time.h>
-#include <LibC/stdio.h>
+#include <time.h>
+#include <stdio.h>
+#include <string.h>
 
 int main(int argc, char** argv)
 {
-    (void) argc;
-    (void) argv;
-
     time_t now = time(nullptr);
+
+    if (argc == 2 && !strcmp(argv[1], "-u")) {
+        printf("%u\n", now);
+        return 0;
+    }
+
     auto* tm = localtime(&now);
     printf("%4u-%02u-%02u %02u:%02u:%02u\n",
         tm->tm_year + 1900,