'===========================================================================
' Subject: CONVERT UNIX TIME STAMP            Date: 10-14-96 (17:32)       
'  Author: Andrew K. Dart                     Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: DATETIME.ABC
'===========================================================================
'Note:  My real name is Andrew K. Dart.  (Required by the rules!)

'I'm sure by now you've been flooded with replies to your question about
'UNIX time stamps, where the date and time is represented by a long
'integer indicating the number of seconds past midnight, 1/1/1970.
'I would have replied sooner, but there was ideal kite-flying weather
'yesterday!  Here's what I've pieced together for you:

REM Program converts UNIX-style date code into day and time.
REM The date code is expressed in the number of seconds since
REM midnight, January 1, 1970.

REM Written 10/14/96 by Andrew K. Dart         PUBLIC DOMAIN
REM Provided as a public service, with no guarantees.
REM If you're still using UNIX after 12/31/99,
REM you'll need to make a few modifications.

DIM LastDay(69 TO 99)
LastDay(69) = 0
FOR x = 70 TO 99
   LastDay(x) = 365 + LastDay(x - 1)
   IF x MOD 4 = 0 THEN LastDay(x) = LastDay(x) + 1
NEXT x

DIM mo(12)
FOR x = 1 TO 12
   READ mo(x)
NEXT x
DATA 0,31,59,90,120,151,181,212,243,273,304,334

INPUT "What is the date code"; Code&
REM maximum allowable date code is LastDay(99) * 86400
REM which is 946,684,800 seconds after 00:00 on 1/1/70.

Days = Code& \ 86400
FOR x = 70 TO 99
   IF Days <= LastDay(x) THEN EXIT FOR
NEXT x
'PRINT USING "Apparently this was sometime in 19##."; x

FOR y = 1 TO 11
   IF Days < (LastDay(x - 1) + mo(y + 1)) THEN
      PRINT "The date was "; STR$(y); "/";
      PRINT RIGHT$(STR$(100 + Days - LastDay(x - 1) - mo(y) + 1), 2);
      PRINT "/"; RIGHT$(STR$(100 + x), 2)
      EXIT FOR
   END IF
NEXT y

REM Now let's figure out what the time of day was:
RawSeconds = Code& MOD 86400
Hour = RawSeconds \ 3600
Minute = (RawSeconds - (Hour * 3600)) \ 60
Second = RawSeconds MOD 60
PRINT "The time was ";
PRINT USING "##:"; Hour;
PRINT RIGHT$(STR$(100 + Minute), 2); ":";
PRINT RIGHT$(STR$(100 + Second), 2)
END

'==============   END   ===============

'I presume that you do not want to account for Leap Seconds,
'because the computer clock (on the system running UNIX) probably does
'not count them.  However if you wanted to use a program like this to
'figure the exact number of seconds between two times, on two different
'dates, you would need to find out whether one or more leap seconds had
'occurred between the two dates.   For details on leap seconds,
'E-Mail me at
'               andrew.dart@chrysalis.org
