Cover V03, I03
Article
Listing 1
Sidebar 1
Table 1
Table 2

may94.tar


Sidebar: About whattime.c

The program whattime.c (Listing 1) takes sets of numbers from the command line and interprets them as seconds elapsed from the epoch date. The ctime() function does the interpreting. The third parameter to the strtol() function, a zero, represents the radix used to interpret the command line numbers. This radix lets you type a regular decimal number, but if you type a leading zero the program will take your number as octal. If you type a leading 0x instead, the number is hexadecimal. You may type a leading minus sign to represent negative numbers, even in front of octal or hexadecimal numbers.

Try whattime 0 to see the epoch start date. Unless you're on Greenwich Mean Time, you'll see a different date and time than the standard midnight, Jan 1, 1970 epoch. For instance, if you're on Pacific Standard Time, you'll see Wed Dec 31 16:00:00 1969, eight hours earlier. If you're on Eastern Standard Time, you'll see the time five hours earlier. In other words, the time is always corrected to your local time zone. This correction has a side effect: the meaningful minimum and maximum values allowed are different from what the 32 bits allow for the time range. If you're west of the Prime Meridian (GMT) the minimum is smaller by the amount of hours west you are, but the maximum doesn't change. If you're east, the maximum is smaller by the amount of hours east you are. For example, Pacific Standard Time is eight hours west (TZ=PST8), so the minimum is 28,800 seconds shorter (-2,147,454,848), while Middle (or Central) European Time is one hour east (TZ=MET-1), so the maximum is 3,600 seconds shorter (2,147,480,047).

To see the GMT dates used in this article you must set your TZ environment variable to GMT. If you're using Bourne Shell (sh) or Korn Shell (ksh), you can type the set command to see your environment variable settings. If you're using C-Shell (csh), type env instead. If you have lots of environment variables, you can type echo $TZ in any of the shells to see only the TZ variable. Then, sh or ksh users should type TZ=GMT; export TZ, while csh users should type setenv TZ GMT. When you're finished experimenting with the whattime program, you can reset TZ to your usual setting. (The /etc/TIMEZONE file has the standard setting for your system.) Don't forget to export if you use sh or ksh. If you simply logout, the TZ variable will be restored to its normal setting from the /etc/TIMEZONE file the next time you login.