Timekeeping in ANSI C

David Chase rbbb at acornrc.UUCP
Thu Feb 11 04:59:18 AEST 1988


I'm in the middle of porting a C library from one machine to another.  In this
library, time is represented as a structure containing two unsigned long
quantities (hi and lo).  The time is encoded as:

	hi contains (centi-seconds since 1900 began) / 65536
		    The high order bit on indicates a bogus time.

	lo contains ((centi-seconds since 1900 began) % 65536) * 65536 +
		    left-over microseconds.

OR	cccccccc ccccuuuu
	hi	 lo

This structure can encode dates from 1900 AD to something like 47000 AD.
It is a pill to work with, of course, which is why you write a bunch of
library routines to work with the time structures (add, subtract, convert
to and from a date+time form, etc).

But don't listen to me.  Go ahead, use the Unix format.  I should still be
alive on 'Mon Jan 18 19:14:07 2038 (GMT)' when all you code dies.  I'll gloat.

David Chase
Olivetti Research Center, Menlo Park



More information about the Comp.lang.c mailing list