- time_t ts;
- struct tm *tm;
- char buf[BUFSIZE];
-
- ts = seconds + (nanoseconds / 1000000000);
- nanoseconds %= 1000000000;
- if (NULL == (tm = gmtime(&ts)))
- ND_PRINT("gmtime() error");
- else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
- ND_PRINT("strftime() error");
- else
- ND_PRINT("%s.%09u", buf, nanoseconds);
+ const time_t ts = seconds;
+ char buf[sizeof("-yyyyyyyyyy-mm-dd hh:mm:ss")];
+
+ ND_PRINT("%s.%09u",
+ nd_format_time(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S",
+ gmtime(&ts)), nanoseconds);
+ if (nanoseconds > ND_NANO_PER_SEC - 1)
+ ND_PRINT(" " ND_INVALID_NANO_SEC_STR);