From: Kenneth Heitke Date: Fri, 5 Apr 2019 18:18:30 +0000 (-0600) Subject: Print timestamp as a date and time string X-Git-Tag: v1.8~9^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a944f4d1af2ac360a66074cf9339c1139775b99d;p=users%2Fsagi%2Fnvme-cli.git Print timestamp as a date and time string Signed-off-by: Kenneth Heitke --- diff --git a/nvme-print.c b/nvme-print.c index 14276824..cfe88e3b 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "nvme-print.h" #include "json.h" @@ -1845,7 +1846,14 @@ static void show_auto_pst(struct nvme_auto_pst *apst) static void show_timestamp(struct nvme_timestamp *ts) { - printf("\tThe timestamp is : %"PRIu64"\n", int48_to_long(ts->timestamp)); + struct tm *tm; + char buffer[32]; + time_t timestamp = int48_to_long(ts->timestamp) / 1000; + + tm = localtime(×tamp); + strftime(buffer, sizeof(buffer), "%c %Z", tm); + + printf("\tThe timestamp is : %"PRIu64" (%s)\n", int48_to_long(ts->timestamp), buffer); printf("\t%s\n", (ts->attr & 2) ? "The Timestamp field was initialized with a "\ "Timestamp value using a Set Features command." : "The Timestamp field was initialized "\ "to ‘0’ by a Controller Level Reset.");