Using struct tm, time_t, and time to create a simple clock

Submitted by:J Kamy81

Date added:19 August, 2018

Category:C

C source code example for using struct tm, time_t, and time to create a simple clock

Tags: clock

Code Snippet:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main()
{
struct tm *tmp;
time_t s;
time(&s);
tmp = localtime(&s);
printf("%2.2d:%2.2d:%2.2d\n",tmp->tm_hour,tmp->tm_min,tmp->tm_sec);
return 0;
}
 
 

Comments