1 /* 2 * Copyright (c) 1985 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)get_date.c 5.3 (Berkeley) 02/27/89"; 20 #endif /* not lint */ 21 22 #include <stdio.h> 23 #include <sys/time.h> 24 25 static char *days[] = { 26 "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" 27 }; 28 29 static char *months[] = { 30 "Jan", "Feb", "Mar", "Apr", "May", "June", 31 "July", "Aug", "Sept", "Oct", "Nov", "Dec" 32 }; 33 34 #define AM "am" 35 #define PM "pm" 36 37 get_date(datebuffer) 38 char *datebuffer; 39 { 40 struct tm *localtime(), *tmp; 41 struct timeval tv; 42 int realhour; 43 char *zone; 44 45 gettimeofday(&tv, 0); 46 tmp = localtime(&tv.tv_sec); 47 48 realhour = tmp->tm_hour; 49 zone = AM; /* default to morning */ 50 if (tmp->tm_hour == 0) 51 realhour = 12; /* midnight */ 52 else if (tmp->tm_hour == 12) 53 zone = PM; /* noon */ 54 else if (tmp->tm_hour >= 13 && tmp->tm_hour <= 23) { /* afternoon */ 55 realhour = realhour - 12; 56 zone = PM; 57 } 58 59 /* format is '8:10pm on Sunday, 16 Sept 1973' */ 60 61 (void)sprintf(datebuffer, "%d:%02d%s on %s, %d %s %d", 62 realhour, 63 tmp->tm_min, 64 zone, 65 days[tmp->tm_wday], 66 tmp->tm_mday, 67 months[tmp->tm_mon], 68 1900 + tmp->tm_year); 69 } 70