Time

Marc A. Murison, RG murison at cfa.HARVARD.EDU
Fri Feb 8 01:24:17 AEST 1991


>From article <8258 at castle.ed.ac.uk>, by james at castle.ed.ac.uk (J Gillespie):
> 
> Is there a simple way of getting hold of the system time from within a
> C program?

Here's how I do it:

#include <time.h>
#include <stdio.h>
void main( void )
{
    time_t  cur_time;

    /* get the current date and time */
    time(&cur_time);

    /* ctime() converts a value of type time_t to a string */
    printf( "\ncurrent time = %s", ctime(&cur_time) );
}


Marc Murison
Smithsonian Astrophysical Observatory
murison at cfacx2.harvard.edu   (the address in the header will bomb)



More information about the Comp.lang.c mailing list