/* Showtime.c (c) Kari Laitinen http://www.naturalprogramming.com/ 2013-11-28 File created. 2013-11-28 Last modification. */ #include #include void get_current_time( int* hours, int* minutes, int* seconds ) { time_t current_time ; time( ¤t_time ) ; *hours = localtime( ¤t_time ) -> tm_hour ; *minutes = localtime( ¤t_time ) -> tm_min ; *seconds = localtime( ¤t_time ) -> tm_sec ; } void get_current_date( int* day_of_month, int* month_index, int* current_year, int* day_of_week_index ) { time_t current_time ; time( ¤t_time ) ; *day_of_month = localtime( ¤t_time ) -> tm_mday ; *month_index = localtime( ¤t_time ) -> tm_mon ; *current_year = localtime( ¤t_time ) -> tm_year + 1900 ; *day_of_week_index = localtime( ¤t_time ) -> tm_wday ; } int main() { char* names_of_days_of_week[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" } ; char* names_of_months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } ; int current_hours, current_minutes, current_seconds, current_day, current_month, current_year, day_of_week ; get_current_time( ¤t_hours, ¤t_minutes, ¤t_seconds ) ; get_current_date( ¤t_day, ¤t_month, ¤t_year, &day_of_week ) ; printf( "\n Current time is: %02d:%02d:%02d\n", current_hours, current_minutes, current_seconds ) ; printf( "\n Current date is: %s, day %d of %s in year %d.\n", names_of_days_of_week[ day_of_week ], current_day, names_of_months[ current_month ], current_year ) ; }