Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!romp!auschs!awdprime!piobe.austin.ibm.com!sjb From: sjb@piobe.austin.ibm.com (Scott J Brickner) Newsgroups: comp.lang.c Subject: Re: time functions Message-ID: <8432@awdprime.UUCP> Date: 12 Jun 91 21:59:53 GMT References: <6583@graphite14.UUCP> Sender: news@awdprime.UUCP Reply-To: sjb@piobe.austin.ibm.com Distribution: comp Organization: IBM Austin, Contractor Lines: 30 In article <6583@graphite14.UUCP>, johnsonl@motcid.UUCP (Lisa A. Johnson) writes: > I'm trying to write a program that finds the local time using the > functions in time.h. I don't care about the date, I just want the > time, but I can't figure out how to do it. Can anyone out there > help? Which functions do I have to use, and what kind of variables > do I need? Try using time() and localtime(), thusly: #include main() { time_t t; struct tm *tm; time( &t); /* t now contains seconds since 00:00 Jan 1, 1970 on UNIX */ tm = localtime( &t); printf( "%02d:%02d:%02d\n", tm->tm_hour, tm->tm_min, tm->tm_sec); } "t" may have seconds (or some other unit) since some other epoch date on non-UNIX systems, but localtime() should compensate for this. Hope it helps... Scott J Brickner