[comp.unix.questions] How to generate Unix time from dates?

jtn@ADS.COM (John T. Nelson) (10/26/90)

For a project I'm working on I'd like to generate an unsigned long
which contains the time of day on Unix systems.  This amounts to usec
in the Unix time.h time_val struct I think.

Is there an algorithm for doing this?  For example I would like to
generate the time for Jan 1 1970 or Jan 1 1904.  Does this algoirthm
also take into acount leap years and LEAP SECONDS?  Are there other
wierdnesses to worry about?

By the way, I know the epoch began in 1970 but there are reasons I
would also like to generate time from 1904 and still state it in Unix
time format in usec's.

Please respond by mail since are news capability is down.  Thanks.



--

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ORGANIZATION:  Advanced Decision Systems   GEOGRAPHIC: Arlington, VA
UUCP:          kzin!speaker@mimsy.umd.edu  INTERNET:   jtn@potomac.ads.com

cpcahil@virtech.uucp (Conor P. Cahill) (10/26/90)

In article <9X5%Q7*@ads.com> jtn@ADS.COM (John T. Nelson) writes:
>For a project I'm working on I'd like to generate an unsigned long
>which contains the time of day on Unix systems.  This amounts to usec
>in the Unix time.h time_val struct I think.

The value returned by time(2) is the number of seconds (not microsecs) that
have past since 12 Midnight December 31, 1969 GMT.  There is no way to use
this value to represent date/times prior to that date.

You will have to come up with a different mechanism to represent these
dates. 

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

shwake@raysnec.UUCP (Ray Shwake) (10/29/90)

cpcahil@virtech.uucp (Conor P. Cahill) writes:

>The value returned by time(2) is the number of seconds (not microsecs) that
>have past since 12 Midnight December 31, 1969 GMT.  There is no way to use
>this value to represent date/times prior to that date.

	Some time back I wrote a 'unixtime' utility which generated both
ASCII and long integer UNIX times, plus supported "time shifts" in hours,
minutes and seconds. Source and manual page available to those interested.
Doesn't, however, support time before UNIX time 0L noted above.

goudreau@dg-rtp.dg.com (Bob Goudreau) (10/30/90)

In article <1990Oct26.132604.16236@virtech.uucp>, cpcahil@virtech.uucp
(Conor P. Cahill) writes:
> 
> The value returned by time(2) is the number of seconds (not
> microsecs) that have past since 12 Midnight December 31, 1969 GMT.

Minor nit:  the Epoch is actually midnight (00:00) of January 1,
1970 UCT (which is the same as GMT).

----------------------------------------------------------------------
Bob Goudreau				+1 919 248 6231
Data General Corporation
62 Alexander Drive			goudreau@dg-rtp.dg.com
Research Triangle Park, NC  27709	...!mcnc!rti!xyzzy!goudreau
USA