Cover V12, I07
jul2003.tar

Listing 6 get_date_from_secs.c

/* 
  get_date_from_secs.c 
  pass the number of seconds since
  the Epoch, and return a Gregorian
  date argument
*/
#include <stdio.h>
#include <time.h>

void main(int argc, char **argv)
{
char *secarg;
struct tm rettm;
time_t now;

/* grab the first argument, time in seconds */
if((secarg = *++argv) == NULL)
   { /* error */
   printf("-1"); 
   exit(1);
   }
else
   {
   if((now=atol(secarg)) == NULL)
      { /* error */
      printf("-2"); 
      exit(1);
      }
   else
      {
      rettm=*localtime(&now);
      printf("%s", asctime(&rettm)); 
/*printf("%2d/%d/%d", rettm.tm_mon+1, rettm.tm_mday, rettm.tm_year+1900); */
      }
   }
exit(0);
}