Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C Programming Exercises, Practice, Solution : Date Time

C Date Time [10 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

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

Expected Output :

The Current date and 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:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



C Programming: Tips of the Day

Static variable inside of a function in C

The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().

The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.

The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().

Ref : https://bit.ly/3fOq7XP