Home > Programming > How To – Get Current Time in C

How To – Get Current Time in C

December 27th, 2014

C Code to fetch current system timestamp

#include
#include

int main ()
{
time_t rawtime;
struct tm * timeinfo;

time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( “Current local time and date: %s”, asctime (timeinfo) );

return 0;
}

Another simple method is to use ctime

#include
#include

int main(void)
{
time_t mytime;
mytime = time(NULL);
printf(ctime(&mytime));

return 0;
}

Be Sociable, Share!
Categories: Programming Tags:

Comments Closed

Comments are closed.