Annotation of coherent/d/usr/src/examples/localtime.c, revision 1.1.1.1

1.1       root        1: #include <time.h>
                      2: #include <sys/types.h>
                      3: 
                      4: char *month[] = {
                      5:        "January", "February", "March", "April",
                      6:        "May", "June", "July", "August", "September",
                      7:        "October", "November", "December"
                      8: };
                      9: 
                     10: char *weekday[] = {
                     11:        "Sunday", "Monday", "Tuesday", "Wednesday",
                     12:        "Thursday", "Friday", "Saturday"
                     13: };
                     14: 
                     15: main()
                     16: {
                     17:        char buf[20];
                     18:        time_t tnum;
                     19:        struct tm *ts;
                     20:        int hour = 0;
                     21: 
                     22:        time(&tnum);    /* get time from system */
                     23: 
                     24:        /* convert time to tm struct */
                     25:        ts=localtime(&tnum);
                     26: 
                     27:        if (ts->tm_hour==0)
                     28:                sprintf(buf,"12:%02d:%02d A.M.",
                     29:                        ts->tm_min, ts->tm_sec);
                     30:        else
                     31:                if (ts->tm_hour>=12) {
                     32:                        hour=ts->tm_hour-12;
                     33:                        if (hour==0)
                     34:                                hour=12;
                     35:                        sprintf(buf,"%02d:%02d:%02d P.M.",
                     36:                                hour, ts->tm_min,ts->tm_sec);
                     37: 
                     38:                } else
                     39:                        sprintf(buf,"%02d:%02d:%02d A.M.", ts->tm_hour,
                     40:                                ts->tm_min,ts->tm_sec);
                     41: 
                     42:        printf("\n%s %d %s 19%d %s\n",
                     43:                weekday[ts->tm_wday], ts->tm_mday,
                     44:                month[ts->tm_mon], ts->tm_year, buf);
                     45: 
                     46:        printf("Today is the %d day of 19%d\n",
                     47:                ts->tm_yday, ts->tm_year);
                     48: 
                     49:        if (ts->tm_isdst)
                     50:                printf("Daylight Saving Time is in effect\n");
                     51:        else
                     52:                printf("Daylight Saving Time is not in effect\n");
                     53: }      

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.