#include <time.h>
#include <stdio.h>

const char MONTH_OF_YEAR[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
const char DAY_OF_WEEK[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };

int main(int argc, char *argv[])
{
  time_t t;
  struct tm *stm;

  if(-1 != (t = time(NULL)))
  {
    printf("Number of seconds since the Unix epoch: %lu\n", t);

    printf(" ctime(%lu) => %s", t, ctime(&t));
    if(NULL != (stm = localtime(&t)))
    {
      printf(" localtime(%lu) =>\n", t);
      printf("                 raw     adjusted\n");
      printf("  Seconds      : %-7d %-7d\n", stm->tm_sec,
                                             stm->tm_sec);
      printf("  Minutes      : %-7d %-7d\n", stm->tm_min,
                                             stm->tm_min);
      printf("  Hours        : %-7d %d %s\n", stm->tm_hour,
                                              stm->tm_hour % 12,
                                              stm->tm_hour / 12 ? "PM" : "AM");
      printf("  Day of Month : %-7d %-7d\n", stm->tm_mday,
                                             stm->tm_mday);
      printf("  Month        : %-7d %-7s\n", stm->tm_mon,
                                             MONTH_OF_YEAR[stm->tm_mon]);
      printf("  Year         : %-7d %-7d\n", stm->tm_year,
                                             stm->tm_year + 1900);
      printf("  Day of Week  : %-7d %-7s\n", stm->tm_wday,
                                             DAY_OF_WEEK[stm->tm_wday]);
      printf("  Day of Year  : %-7d %-7d\n", stm->tm_yday,
                                             stm->tm_yday + 1);
      printf("  Is DST       : %-7d %-7s\n", stm->tm_isdst,
                                             stm->tm_isdst > 0 ? "yes" : "no");
    }
  }
  else
    printf("ERROR: Call to time() failed.\n");

  return(0);
}