Time

Rana Raychoudhury rana at hpqtdla.sqf.hp.com
Thu Feb 7 04:31:09 AEST 1991


> 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 at 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.h>

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-



More information about the Comp.lang.c mailing list