Print current date and time in C

Write a C program to print current date and time in standard output.

 

We know that time.h header file contains definitions of functions to get and manipulate date and time information. The following C source code prints the current date and time to the standard output stream using tm structure which holds calendar date and time broken down into its components.

 
C implementation –
 

Download   Run Code

Output:

Today is : Sun Apr 2 23:23:59 2017
Time is : 11:23:59 pm
Date is : 02/04/2017

 

In C++ 11, we can also use std::chrono::system_clock::now() which returns a time point representing the current point in time.

 
Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Leave a Reply

Notify of
avatar
wpDiscuz