--- On Sun, 1/2/11, Peter <[email protected]> wrote:
From: Peter <[email protected]> Subject: Re: [MLUG] Date Routines in Linux C To: "Montreal Linux Users Group" <[email protected]> Date: Sunday, January 2, 2011, 11:37 AM short version: man ctime. longer version: lola% more now.c #include <stdio.h>#include <time.h> int main(int argc, char *argv[]) { time_t now; struct tm *d; time(&now); printf("hello world. It is now %10ld seconds since the epoch began\n", now); d = localtime(&now); printf("for mere humans, today is: %d/%d/%d\n", 1900+d->tm_year,d->tm_mon, d->tm_mday );} lola% lola% ./nowhello world. It is now 1293986153 seconds since the epoch beganfor mere humans, today is: 2011/0/2lola% On Sun, Jan 2, 2011 at 10:18 AM, Leslie S Satenstein <[email protected]> wrote: Happy New Year. I have been trying to find a simple example to retrieve the computer date using documented routines. I want to retrieve three integers corresponding to year, month and day. I took the time() function and subtracted the number of seconds we are behind GMT 0, and converted seconds to days since 1979-01-01 >From there I did calculate the current date. However, rather than supporting >my own code, I would have liked to have use localtime(), and time(), etc, >but... I get compile errors for tm->year, tm->mon and tm->mday. Searching the includes, results in no function that returns the integters Ditto for a google search. Any standard function to complete and return the tm structure as defined in time.h would be appreciated. I can get a string with the standard C library. What I want is a set of integer values for year, month day. Ctime, ascitime, strftime etc only provide strings. This is the function I have written ================== void todaysDate(int *y,int *m, int *d) { time_t t; long jour; time_t GMT_ADJ; GMT_ADJ = -5; // Montreal = GMT -5 // jour=GToJulian(1970,1,1); // 2440588 t=time(NULL) + (GMT_ADJ*60*60); // Timezone adjustment in Seconds jour = 2440588 + t/(1440*60); //1440 minutes in a day JToGregorian(jour,y,m,d); //1440 minutes in a day } The JToGregorian is a function that takes the Julian Date and converts it to a Gregorian Calendar date. I really want to use the system function(s). ------------------ Regards Leslie Mr. Leslie Satenstein 40 years in IT and going strong. Yesterday was a good day, today is a better day, and tomorrow will be even better. mailto:[email protected] alternative: [email protected] www.itbms.biz / www.eclipseguard.com _______________________________________________ mlug mailing list [email protected] https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca
