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
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.
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
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
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
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
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
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)
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
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
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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework