Commit | Line | Data |
---|---|---|
810b1430 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
166793b0 | 7 | #ifndef lint |
9bd38ba8 | 8 | static char sccsid[] = "@(#)get_date.c 5.2 (Berkeley) %G%"; |
810b1430 | 9 | #endif not lint |
166793b0 RC |
10 | |
11 | #include <stdio.h> | |
12 | #include <sys/time.h> | |
13 | ||
14 | static char *days[] = { | |
15 | "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" | |
16 | }; | |
17 | ||
18 | static char *months[] = { | |
19 | "Jan", "Feb", "Mar", "Apr", "May", "June", | |
20 | "July", "Aug", "Sept", "Oct", "Nov", "Dec" | |
21 | }; | |
22 | ||
23 | #define AM "am" | |
24 | #define PM "pm" | |
25 | ||
26 | get_date(datebuffer) | |
27 | char *datebuffer; | |
28 | { | |
29 | struct tm *localtime(), *tmp; | |
30 | struct timeval tv; | |
31 | int realhour; | |
32 | char *zone; | |
33 | ||
34 | gettimeofday(&tv, 0); | |
35 | tmp = localtime(&tv.tv_sec); | |
36 | ||
37 | realhour = tmp->tm_hour; | |
38 | zone = AM; /* default to morning */ | |
39 | if (tmp->tm_hour == 0) | |
40 | realhour = 12; /* midnight */ | |
41 | else if (tmp->tm_hour == 12) | |
42 | zone = PM; /* noon */ | |
43 | else if (tmp->tm_hour >= 13 && tmp->tm_hour <= 23) { /* afternoon */ | |
44 | realhour = realhour - 12; | |
45 | zone = PM; | |
46 | } | |
47 | ||
48 | /* format is '8:10pm on Sunday, 16 Sept 1973' */ | |
49 | ||
9bd38ba8 | 50 | (void)sprintf(datebuffer, "%d:%02d%s on %s, %d %s %d", |
166793b0 RC |
51 | realhour, |
52 | tmp->tm_min, | |
53 | zone, | |
54 | days[tmp->tm_wday], | |
55 | tmp->tm_mday, | |
56 | months[tmp->tm_mon], | |
57 | 1900 + tmp->tm_year); | |
58 | } |