SUMMARY: TIME FORMAT & C2

From: Douglas Meldrum <arn_at_oracle.dsuper.net>
Date: Tue, 22 Jul 1997 15:12:58 -0400 (EDT)

Morning,

Thanks to the quick replies of :

Brian H. Mayo <brian.mayo_at_brynmawr.edu> who suggested wirting up a PERL
SCRIPT

Paul A Sand <pas_at_cisunix.unh.edu> whos gave forth the following command:
perl -e 'print scalar localtime 867287140, "\n";' and suggested the usage
of "strftime"

Randy M. Hayman <haymanr_at_icefog.sois.alaska.edu> who was kind enough to
send me a C program to do the conversion ( see --secs2date -- )

All of the above satisfie my needs. Thanks again to those above for the help.

      ._._._.
  Douglas Meldrum
Network Coordinator
  Delphi Supernet
     H.S.A.I.T.
      .-.-.-.
PENDING: Summary on Disabling System Accounts
REASON: Still lacking information.



-----------------secs2date--------------------------------

#include <stdio.h> /* printf() */
#include <sys/time.h> /* localtime() */

static char *weekday[7] = {"Sun","Mon","Tues","Wed","Thu","Fri","Sat"};
static char *month[12] =
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
struct tm *time_struct;
char date_str[32] = NULL;
time_t seconds;

main(int argc, char *argv[])
{

        if( !argv[1] ) {
                fprintf(stdout, "usage: %s <secs since epoch>\n", argv[0]);
                exit(1);
        }

        (time_t)seconds = atoi(*++argv);
        time_struct = localtime(&seconds);

        sprintf(&date_str[0], " %s %02d %s %04d %d:%02d:%02d",
                weekday[time_struct->tm_wday], time_struct->tm_mday,
                month[time_struct->tm_mon], time_struct->tm_year + 1900,
                time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec);

        fprintf(stdout, "\t%u seconds post-epoch is %s\n", seconds, date_str);

        exit(0);
}
------------------------8<----------------------------


$ cc -o secs2date secs2date.c
$ secs2date 867287140
        867287140 seconds post-epoch is Wed 25 Jun 1997 17:05:40
Received on Tue Jul 22 1997 - 21:26:48 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:36 NZDT