SUMMARY: Timestamp (number of seconds since 1-1-1970 00:00:00)

From: Francisco Javier Arias Correa (NIC) (farias@nic.mx)
Date: Mon Jul 20 1998 - 12:44:40 CDT


Thanks to:

        Greg Sawicki <sawicki@interlog.com>
        kylet@shore.net (Kyle Tucker)
        jrs@net.com (John Switzer)
        "Arthur A. Lehmann" <aalehma@lava.net>
        Lars Balker Rasmussen <lbr@mjolner.dk>
        Jeff Wasilko <jeffw@shore.net>
        Gary Chambers <geecee@netquarters.net>
        Seth Rothenberg <SROTHENB@montefiore.org>
        Charles Roten <croten@ceiba.netsis.com>
        Greg Onufer <Greg.Onufer@Eng.Sun.COM>
        Charlie Mengler <charliem@anchorchips.com>

1) Using perl:

        a) perl -e 'print time'

        b) #!/usr/local/perl/bin/perl
                # This converts UTC (on the commandline) to UNIX date/time format
                require 'ctime.pl';
                print &ctime($ARGV[0]);

2) Using c:

        a) From Greg Sawicki:
                #include <stdio.h>
                #include <time.h>
                void main(int argc, char* argv[])
                {
                        time_t mem_ptr, timestamp;
                        timestamp = time(&mem_ptr);
                        fprintf(stdout, "%ld\n", timestamp);
                }

        b) From: Kyle Tucker
                /* program to seconds since epoque */
                #include <stdio.h>
                #include <time.h>
                main()
                {
                        long *ltime;
                        time(&ltime);
                        printf("%i\n", ltime);
                        exit(0);
                }

                /* date given seconds */
                #include <stdio.h>
                #include <sys/types.h>
                #include <time.h>
                #include <string.h>
                main(argc, argv)
                char *argv[];
                int argc;
                {
                        if ( argc == 2 )
                           {
                            long ltime;
                            int epoch;
                            char *date;
                            char dateline[28];
                            time(&ltime);
                            epoch = atoi(argv[1]);
                            date = ctime(&epoch);
                            printf("%s", date);
                            }
                        else
                            {
                            printf("Epoch argument please\n");
                            }
                }

3) Install GNU sh-utils:

        % date +%s
        900739888
        % date --help | grep %s
          %s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)

----------------------

        Francisco Arias



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:44 CDT