w3resource logo


C Programming Exercises

C Programming Exercises, Practice, Solution : Date Time

Secondary Nav

C Date Time [10 exercises with solution]

1. Write a program in C to print the current time. Go to the editor

Expected Output :

The Current time is : Tue Sep  6 11:47:52 2016

Click me to see the solution

2. Write a program in C to compute the number of seconds passed since the beginning of the month. Go to the editor

Expected Output :

475179 seconds passed since the beginning of the month.

Click me to see the solution

3. Write a program in C to convert a time_t object to a textual representation. Go to the editor

Expected Output :

Tue Sep  6 12:20:53 2016 

Click me to see the solution

4. Write a program in C to convert a tm object to custom textual representation. Go to the editor

Expected Output :

The textual representation of specified date and time :                
September Sun Sep  2 16:30:32 2016 pm                                   
September Sun Sep  2 16:30:32 2016 pm 

Click me to see the solution

5. Write a program in C to convert a tm object to custom wide string textual representation. Go to the editor

Expected Output :

Sunday Sun Sep  2 17:51:10 2016                                         
Sunday Sun 02 Sep 2016 05:51:10 PM IST

Click me to see the solution

6. Write a program in C to convert a time_t object to calendar time expressed as Coordinated Universal Time. Go to the editor

Expected Output :

The calendar time expressed as Coordinated Universal Time is :          
UTC:   Tue Sep  6 08:18:10 2016                                         
local: Tue Sep  6 13:48:10 2016

Click me to see the solution

7. Write a program in C to convert a time_t object to calendar time expressed as local time. Go to the editor

Expected Output :

The calendar time expressed as a local Time is :                        
UTC:   Tue Sep  6 08:35:25 2016                                         
local: Tue Sep  6 14:05:25 2016

Click me to see the solution

8. Write a program in C to print the date and time before 24 months. Go to the editor

Expected Output :

Today is :          Tue Sep  6 14:26:56 2016                            
(DST is not in effect)                                                  
                                                                        
24 months ago the date was : Sat Sep  6 14:26:56 2014                   
(DST was not in effect)

Click me to see the solution

9. Write a program in C to show the first of calendar time. Go to the editor

Expected Output :

Mon Jan  1 00:00:00 1900

Click me to see the solution

10. Write a program in C to show the start of the epoch. Go to the editor
Note : epoch means the beginning of a period in the history of someone.

Expected Output :

0 seconds since the epoch began                                         
Thu Jan  1 00:00:00 1970

Click me to see the solution

Practice online

#include <stdio.h> 
 int main()  
  {

  }

List of Exercises with Solutions :



Join our Question Answer community to learn and share your programming knowledge.