1 /* $NetBSD: humandate.c,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
4 * humandate - convert an NTP (or the current) time to something readable
8 #include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */
9 #include "lib_strbuf.h"
10 #include "ntp_stdlib.h"
12 static const char *months
[] = {
13 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
14 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
16 static const char *days
[] = {
17 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
28 tm
= ntp2unix_tm(ntptime
, 1);
31 return "--- --- -- ---- --:--:--";
35 (void) sprintf(bp
, "%s, %s %2d %4d %2d:%02d:%02d",
36 days
[tm
->tm_wday
], months
[tm
->tm_mon
], tm
->tm_mday
,
37 1900+tm
->tm_year
, tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
43 /* This is used in msyslog.c; we don't want to clutter up the log with
44 the year and day of the week, etc.; just the minimal date and time. */
50 time_t cursec
= time((time_t *) 0);
53 tm
= localtime(&cursec
);
55 return "-- --- --:--:--";
59 (void) sprintf(bp
, "%2d %s %02d:%02d:%02d",
60 tm
->tm_mday
, months
[tm
->tm_mon
],
61 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);