Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ceco!garry From: garry@ceco.ceco.com (Garry Garrett) Newsgroups: comp.lang.c Subject: Re: Julian date routines needed Summary: julian time Keywords: julian date, C, unix,dos Message-ID: <408@ceco.ceco.com> Date: 20 Feb 91 23:59:13 GMT References: <1753@manta.NOSC.MIL> <1780@manta.NOSC.MIL> Organization: Commonwealth Edison Co., Chicago, IL Lines: 48 In article <1780@manta.NOSC.MIL>, grantk@manta.NOSC.MIL (Kelly J. Grant) writes: > In article <1753@manta.NOSC.MIL>, grantk@manta.NOSC.MIL (Kelly J. Grant) writes: > > Howdy networld > > > > About 100,000 years ago I had some Julian date routines (in dBASE) to > > convert YY/MM/DD into a format suitable for math, and also to convert > > back to normal dates. We called these JULTOCAL and CALTOJUL. I now > > have a need for these algorithms for a UNIX program. Would any of > > you kind souls have these routines lying around in your book of tricks > > [right next to your hanoi.c file maybe :-)] > > Kelly Grant grantk@manta.nosc.mil (619) 225-2508 There is an easy way to do this. Let UNIX do all the work FOR you. #include #include main() { struct tm *tmptr; size_t sec70; tmptr = (struct tm *) malloc(sizeof(struct tm)); /* ... */ sscanf(datestr,"%d/%d/%d",&tmptr->tm_year,&tmptr->tm_mon,&tmptr->tm->mday); /* my UNIX system doesn't seem to mind that the rest of the */ /* fields of tmptr are not filled out. I think that malloc */ /* on my system fills the memory with 0's. Not true on all */ /* systems though. */ sec70 = mktime(tmptr); tmptr = localtime(sec70); /* tmptr->tm_yday now contains the julian day */ } Generally speaking, on a unix system, if you can convert the time that you are given, in whatever format you are given to either structure tm (defined in time.h) or into the number of seconds elapsed since jan 1, 1970 at 00:00:00, then you can do anything you want to with it. Unix is very good about that, but other C compilers do not always have all functions that are available on Unix. Prime is one of those systems. That's why I would like to find the code to mktime() and strftime() (as described in K&R, 2nd edition, p255) so that I can manipulate various reprentations of time. Garry Garrett garry@ceco.ceco.com ...!uunet!ceco.ceco.com!garry