w3resource logo

:

C Programming Exercises

C Programming Exercises, Practice, Solution : Date Time

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 : Thu Aug 03 13:38:58 2017

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 :

 222084 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 :

Thu Aug 03 13:44:49 2017

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 :

 The textual representation of specified date and time :

Sunday 09/02/16 17:51:10
Sunday 09/02/16 17:51:10

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:   Thu Aug 03 10:53:03 2017
local: Thu Aug 03 16:23:03 2017

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:   Thu Aug 03 11:15:59 2017
local: Thu Aug 03 16:45:59 2017

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 :          Thu Aug  3 17:27:16 2017                                                                                  
(DST is not in effect)                                                                                                        
                                                                                                                              
24 months ago the date was : Mon Aug  3 17:27:16 2015                                                                         
(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 :

Sun Jan 01 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 01 00:00:00 1970

Click me to see the solution

C Programming Code Editor: