1 #ifndef lint 2 static char sccsid[] = "@(#)get_date.c 4.1 (Berkeley) 85/02/05"; 3 #endif 4 5 #include <stdio.h> 6 #include <sys/time.h> 7 8 static char *days[] = { 9 "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" 10 }; 11 12 static char *months[] = { 13 "Jan", "Feb", "Mar", "Apr", "May", "June", 14 "July", "Aug", "Sept", "Oct", "Nov", "Dec" 15 }; 16 17 #define AM "am" 18 #define PM "pm" 19 20 get_date(datebuffer) 21 char *datebuffer; 22 { 23 struct tm *localtime(), *tmp; 24 struct timeval tv; 25 int realhour; 26 char *zone; 27 28 gettimeofday(&tv, 0); 29 tmp = localtime(&tv.tv_sec); 30 31 realhour = tmp->tm_hour; 32 zone = AM; /* default to morning */ 33 if (tmp->tm_hour == 0) 34 realhour = 12; /* midnight */ 35 else if (tmp->tm_hour == 12) 36 zone = PM; /* noon */ 37 else if (tmp->tm_hour >= 13 && tmp->tm_hour <= 23) { /* afternoon */ 38 realhour = realhour - 12; 39 zone = PM; 40 } 41 42 /* format is '8:10pm on Sunday, 16 Sept 1973' */ 43 44 sprintf(datebuffer, "%d:%02d%s on %s, %d %s %d", 45 realhour, 46 tmp->tm_min, 47 zone, 48 days[tmp->tm_wday], 49 tmp->tm_mday, 50 months[tmp->tm_mon], 51 1900 + tmp->tm_year); 52 } 53