|
|
1.1 ! root 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: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)get_date.c 5.1 (Berkeley) 4/29/85"; ! 9: #endif not lint ! 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: ! 50: sprintf(datebuffer, "%d:%02d%s on %s, %d %s %d", ! 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: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.