Date and Time Functions in C

Question: What are Date and Time Functions in Standard C Library?

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.

If you wish to look at all C Tutorials, go to C Tutorials.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.