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

This snippet submitted by Dieter Manstein on 2006-10-12. It has been viewed 5093 times.
Rating of 5.3 with 11 votes

#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;
}





More C and C++ source code snippets

Add a snippet!