Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!spool.mu.edu!samsung!sdd.hp.com!hplabs!hpcc05!hpcuhb!hpsqf!hpqtdla!rana From: rana@hpqtdla.sqf.hp.com (Rana Raychoudhury) Newsgroups: comp.lang.c Subject: Re: Time Message-ID: <430014@hpqtdla.sqf.hp.com> Date: 6 Feb 91 17:31:09 GMT References: <8258@castle.ed.ac.uk> Organization: HP, Queensferry Telecomms, Scotland Lines: 51 > Is there a simple way of getting hold of the system time from within a > C program? I've read all the material I can find on time.h, but can't > make head or tail of it, and have had to resort to passing in the time > as a command line argument. This may be a really idiotic question, > -- > James Gillespie, /~~~~~~~~\ > Edinurgh University. / @ @ \ "I'm not musical either - > james@ed.ac.uk / < \ I play the bagpipes" > ____________________/ \________/ \__________________________________________ (I assume you mean "time of day" and are using an ANSI compiler :- [From the 'C Programming Language, 2nd Edition pp256-7] .... char *asctime(const struct tm *tp) converts the time in the structure *tp into a string of the form Sun Jan 3 15:14:13 1988\n char *ctime(const time_t *tp) converts the calendar time *tp to local time; equivalent to :- asctime(localtime(tp)); blah blah blah. Here's a little example :- ---------------- snip snip -------------- #include time_t now; main() { (void) time( &now ); printf("The time is : %s\n", asctime(localtime(&now))); } ---------------- snip snip -------------- which produces something like :- The time is : Wed Feb 6 17:27:15 1991 -rana-