Answer: Standard library gives a nice collection of functions which allow us to deal with date and time related computations. These include ‘clock()’ function which returns amount of processor time used by the program, ‘time()’ function returns no. of seconds from an arbitrary epoch, ‘ctime()’ and ‘asctime()’ functions give current date and day of time as function value, ‘gmtime()’ converts time value into Coordinated Universal Time (UTC). Let’s see their prototypes below
clock_t clock(void); time_t time(time_t *returned value); char *ctime(time_t const *time_value); double difftime(time_t tm1, time_t tm2); char *asctime(struct tm const *tm_ptr); struct tm *localtime(time_t const *time_value); struct tm *gmtime(time_t const *time_value); size_t strftime(char *str, size_t maxsize, char const *format, struct tm const *tm_ptr);
Notice that ‘localtime()’ returns structure of type struct tm that can be passed as an argument to asctime() function. ‘asctime()’ and ‘ctime()’ functions return current date and time of day. Actually, ‘ctime()’ function may call ‘asctime()’ to perform its work.
Sanfoundry Global Education & Learning Series – 1000 C Tutorials.
- Check C Books
- Practice BCA MCQs
- Apply for Computer Science Internship
- Apply for C Internship
- Check Computer Science Books