Seconds from 19xx to Date (and visa

danr at hcx2.SSD.HARRIS.COM danr at hcx2.SSD.HARRIS.COM
Wed Oct 5 23:15:00 AEST 1988


>/* Written 10:18 pm  Oct  3, 1988 by pozar at hoptoad.UUCP in hcx2:comp.lang.c */
 [edited slightly without permission]
>/* ---------- "Seconds from 19xx to Date (and visa" ---------- */
>
>   Does anyone have a routine to change back and forth between
>seconds from 19xx to a Year, Month, Day sort of Date?  
>	     Thanks
>	       Tim
>/* End of text from hcx2:comp.lang.c */

	You might want to look at the man page for ctime(), if you have 
access to one.  it is in the standard library, so you don't need to write 
anything bu the function call.

	char *ctime (clock)
	long *clock;

where clock is a pointer to a long integer containing a number of seconds
since 00:00:00 GMT, January 1, 1970 (when time began...)

CAVEAT:  The return value is to a static buffer, so something like

	printf (" %s %s ", ctime (&time1), ctime (&time2));

will print out ctime (&time[12]) for both (depending on the order of 
evaluation of parameters, should some compiler do it backwards).
If you need to do this, copy one of the ctime() return values to another
string before calling ctime() again.

Hope this will do!!!

-danr at hcx1.ssd.harris.com



More information about the Comp.lang.c mailing list