C comes with a host of functions for reporting the current time. The time() function returns the number of seconds elapsed since January 1, 1970, known as the Unix epoch. The value returned from the time() function is a time_t value. The localtime() function takes a time_t value and returns a tm structure that contains various time elements, such as the hour, minute, day of the month, and so on.
- [Instructor] The computer keeps track of the time … and so can your programs when you use … the C library's time functions. … The time function at line 8 fetches the time … in the time_t variable now declared at line 6. … The variables address is passed to the function, … so the value returned is in the same variable. … Both time and the time_t data type … require the time.h header file, … which is included in this code at line 2. … Build and run. … You were probably expecting … to see the current date and time, … but you are. … This value is known as the UNIX Epoch, … and it's the number of seconds that have ticked … since January 1, 1970. … Let's check out the last part of the value, 2182. … Run again. … And you see it's a new value, … a new number of seconds has elapsed. … Now you don't need to do all the math … to convert the Epoch time into the current time. … Instead this code uses the ctime function, … the end of line nine inside the printf statement. … This function is also prototyped in the time.h header file. …
Author
Released
5/1/2019- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
Duration
Views
Related Courses
-
Learning C
with Dan Gookin3h 16m Beginner -
C Essential Training: 1 The Basics
with Dan Gookin2h 31m Beginner -
Code Clinic: C
with Dan Gookin1h 7m Intermediate
-
Introduction
-
Using the exercise files1m 23s
-
Configuring the IDE2m 34s
-
1. Arrays and Structures
-
Understanding arrays2m 59s
-
Working with arrays3m 5s
-
Modifying arrays3m 11s
-
Building a structure3m 23s
-
Nesting structures2m 56s
-
Understanding a union2m 47s
-
-
2. Characters and Strings
-
Testing characters2m 34s
-
Fetching string input3m 18s
-
Sending string output2m 46s
-
Using printf() placeholders3m 36s
-
Exploring string functions3m 29s
-
Manipulating strings3m 53s
-
Avoiding string problems2m 27s
-
3. Pointers
-
Understanding pointers3m 19s
-
Doing pointer math2m 57s
-
Allocating storage3m 15s
-
Working with a pointer array3m 38s
-
Using pointers in structures3m 30s
-
Returning pointers2m 39s
-
-
4. Files and the Operating System
-
Reading from a file3m 25s
-
Writing to a file3m 24s
-
Working with raw data2m 53s
-
Using random file access2m 47s
-
Manipulating files2m 57s
-
Exploring the path2m 8s
-
Reading a directory2m 53s
-
Getting file information2m 46s
-
Using command line arguments2m 44s
-
Calling the operating system2m 46s
-
-
5. The Interesting and Extraordinary
-
Solving math puzzles3m 32s
-
Creating random numbers3m 42s
-
Working with time functions3m 54s
-
Sorting data4m 8s
-
Using a debugger4m 53s
-
Writing your own header file2m 53s
-
Challenge: Lotto simulation1m 18s
-
Solution: Lotto simulation2m 29s
-
-
Conclusion
-
Next steps1m 52s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Working with time functions