The ISO timestamp has timezone information, and is easily parsable.
}
*/
time(&t);
- mvprintw(1, maxx-25, ctime(&t));
+ mvprintw(1, maxx-25, iso_time(&t));
+ printw("\n");
printw("Keys: ");
attron(A_BOLD); printw("H"); attroff(A_BOLD); printw("elp ");
#include "net.h"
#include "dns.h"
#include "asn.h"
+#include "utils.h"
#define MAXLOADBAL 5
#define MAX_FORMAT_STR 81
extern void report_open(void)
{
const time_t now = time(NULL);
- char *t = ctime (&now);
- const size_t len = strlen(t);
+ const char *t = iso_time (&now);
- if (t[len - 1] == '\n')
- t[len - 1] = '\0';
printf ("Start: %s\n", t);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#ifdef HAVE_ERROR_H
if (close_stream(stderr) != 0)
_exit(EXIT_FAILURE);
}
+
+/* ctime() replacement that will reteturn ISO-8601 timestamp string such as:
+ * 2016-08-29T19:25:02+01:00 */
+extern const char *iso_time(const time_t *t)
+{
+ static char s[32];
+ struct tm *tm;
+
+ tm = localtime(t);
+ strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S%z", tm);
+ return s;
+}
extern char *xstrdup(const char *str);
extern void close_stdout(void);
+
+extern const char *iso_time(const time_t *t);