Annotation of coherent/a/usr/man/MULTI/localtime, revision 1.1.1.1

1.1       root        1: 
                      2: 
                      3: localtime()               Time Function               localtime()
                      4: 
                      5: 
                      6: 
                      7: 
                      8: Convert system time to calendar structure
                      9: 
                     10: #include <time.h>
                     11: #include <sys/types.h>
                     12: ttmm *llooccaallttiimmee(_t_i_m_e_p) ttiimmee_tt *_t_i_m_e_p;
                     13: 
                     14: localtime  converts  the COHERENT  internal  time  into the  form
                     15: described in the structure tm.
                     16: 
                     17: timep points to the system time.   It is of type time_t, which is
                     18: defined in the header file ttyyppeess.hh.
                     19: 
                     20: localtime returns  a pointer to  the structure tm,  which is also
                     21: defined in ttyyppeess.hh.  The  function asctime turns tm into an ASCII
                     22: string.
                     23: 
                     24: Unlike its  cousin gmtime, localtime returns  the local time, in-
                     25: cluding conversion  to daylight saving time,  if applicable.  The
                     26: daylight saving time  flag indicates whether daylight saving time
                     27: is now in effect, not whether it is in effect during some part of
                     28: the  year.  Note,  too, that  the time zone  is set  by localtime
                     29: every time the value returned by
                     30: 
                     31: 
                     32:         getenv("TIMEZONE")
                     33: 
                     34: 
                     35: changes.  See the Lexicon entry for TTIIMMEEZZOONNEE for more information
                     36: on how COHERENT handles time zone settings.
                     37: 
                     38: ***** Example *****
                     39: 
                     40: The following example  recreates the function aassccttiimmee.  It builds
                     41: a  string somewhat  different from  that  returned by  asctime to
                     42: demonstrate how to manipulate the ttmm structure.
                     43: 
                     44: 
                     45: #include <time.h>
                     46: #include <sys/types.h>
                     47: 
                     48: 
                     49: 
                     50: char *month[] = {
                     51:         "January", "February", "March", "April",
                     52:         "May", "June", "July", "August", "September",
                     53:         "October", "November", "December"
                     54: };
                     55: 
                     56: 
                     57: 
                     58: 
                     59: 
                     60: 
                     61: 
                     62: 
                     63: 
                     64: COHERENT Lexicon                                           Page 1
                     65: 
                     66: 
                     67: 
                     68: 
                     69: localtime()               Time Function               localtime()
                     70: 
                     71: 
                     72: 
                     73: char *weekday[] = {
                     74:         "Sunday", "Monday", "Tuesday", "Wednesday",
                     75:         "Thursday", "Friday", "Saturday"
                     76: };
                     77: 
                     78: 
                     79: 
                     80: main()
                     81: {
                     82:         char buf[20];
                     83:         time_t tnum;
                     84:         struct tm *ts;
                     85:         int hour = 0;
                     86: 
                     87: 
                     88: 
                     89:         time(&tnum);    /* get time from system */
                     90: 
                     91:         /* convert time to tm struct */
                     92:         ts=localtime(&tnum);
                     93: 
                     94: 
                     95: 
                     96:         if (ts->tm_hour == 0)
                     97:                 sprintf(buf,"12:%02d:%02d A.M.",
                     98:                         ts->tm_min, ts->tm_sec);
                     99: 
                    100: 
                    101: 
                    102:         else
                    103:                 if(ts->tm_hour>=12) {
                    104:                         hour=ts->tm_hour-12;
                    105:                         if (hour==0)
                    106:                                 hour=12;
                    107:                         sprintf(buf,"%02d:%02d:%02d P.M.",
                    108:                                 hour, ts->tm_min,ts->tm_sec);
                    109: 
                    110: 
                    111: 
                    112:                 } else
                    113:                         sprintf(buf,"%02d:%02d:%02d A.M.", ts->tm_hour,
                    114:                                 ts->tm_min,ts->tm_sec);
                    115: 
                    116: 
                    117: 
                    118:         printf("\n%s %d %s 19%d %s\n",
                    119:                 weekday[ts->tm_wday], ts->tm_mday,
                    120:                 month[ts->tm_mon], ts->tm_year, buf);
                    121: 
                    122: 
                    123: 
                    124: 
                    125: 
                    126: 
                    127: 
                    128: 
                    129: 
                    130: COHERENT Lexicon                                           Page 2
                    131: 
                    132: 
                    133: 
                    134: 
                    135: localtime()               Time Function               localtime()
                    136: 
                    137: 
                    138: 
                    139:         printf("Today is the %d day of 19%d\n",
                    140:                 ts->tm_yday, ts->tm_year);
                    141: 
                    142: 
                    143: 
                    144:         printf("Daylight Saving Time %s in effect\n",
                    145:                 ts->tm_isdst ? "is" : "is not");
                    146: }
                    147: 
                    148: 
                    149: ***** See Also *****
                    150: 
                    151: gmtime(), time, TIMEZONE
                    152: 
                    153: ***** Notes *****
                    154: 
                    155: localtime returns  a pointer to a  statically allocated data area
                    156: that is overwritten by successive calls.
                    157: 
                    158: 
                    159: 
                    160: 
                    161: 
                    162: 
                    163: 
                    164: 
                    165: 
                    166: 
                    167: 
                    168: 
                    169: 
                    170: 
                    171: 
                    172: 
                    173: 
                    174: 
                    175: 
                    176: 
                    177: 
                    178: 
                    179: 
                    180: 
                    181: 
                    182: 
                    183: 
                    184: 
                    185: 
                    186: 
                    187: 
                    188: 
                    189: 
                    190: 
                    191: 
                    192: 
                    193: 
                    194: 
                    195: 
                    196: COHERENT Lexicon                                           Page 3
                    197: 
                    198: 

unix.superglobalmegacorp.com

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