Standard C Library / time.h
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Time has always been a very important part of C, several developers of UNIX were amateur astronomers and they were more meticulous then most about time. But the ability of C to keep track of time depends on the operating system it's running on, so you may not be able to rely on its accuracy. The C Standard set of functions make it possible for you to retrieve the time value and display it in a number of ways, but you should never take the accuracy very seriously. That depends on the underlying system. The most fundamental of the time functions is clock; it returns the best approximation of a processor time. It's the duration since an implementation defined error. To find out when that is you will have to check your documentation. The type of the return value is something that's able to represent the time. If the time is not available the return value is minus 1. This value is the number of times the clock takes per second on this system, the value returned can be divided by the clocks per second to get the number of seconds. The time function returns a current calendar time. If the timer is not a null pointer the value is also assigned to that location. The encoding of the time T Value is unspecified by the C standard. The difftime function computes and returns as a double the difference between 2 calendar times. The C Time Function converts the Time T Value into an ASCII string. It first uses the time zone setting to convert it to the local time then converts that result to ASCII. The output string has a standard form and is always exactly 23 characters long. The local time function converts the contents of a timet object into a struct representing the local time. The struct is defined in the header, it contains members for seconds, minutes, hours, day of the month, month of the year, number of the year, day of the week, day of the year and whether its daylight savings time. The gmtime function converts the timet value into the struct form representing Greenwich Meantime. The ASCII Time function converts the contents of a tm struct to ASCII string. The string is in the same 23 character format as the one returned from ctime. The mktime function converts the contents of the time structure into the values stored in the time tobject. There is a side effect with this function. In the struct the values for day of the week and day of the year are not used in the calculation but they are updated in the struct. Other values in the struct are adjusted to be within valid ranges. This is the last one. This function creates a string from a date and a format specification and places it in a char Array. You can specify the exact format for various date items. For example, percent with a small a is for the abbreviated weekday name and percent with a large A is the full weekday name. I'm not going to go through the entire list, there are 22 of them and you wouldn't remember them anyway, they're in your documentation. The point is you can get the date and time to the accuracy of the underlying operating system and you can put it in whatever form you'd like.
Tutorial Information
| Course: | Advanced C Programming |
| Author: | Arthur Griffith |
| SKU: | 33965 |
| ISBN: | 1-935320-24-6 |
| Release Date: | 2009-01-30 |
| Duration: | 5.5 hrs / 82 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 