Display Current Date and Time C Program

C Program To Display Current Date and Time

Learn How To Display Current Date and Time in C Programming Language. This C Code demonstrates the use of asctime() and strftime() methods in C Programming to Print System Date and Time.

There are numerous built-in Library methods to Print System Date and Time viz., time(), ctime(), strftime(), asctime(), gmtime(), localtime() and many more. All these methods are defined in the Time Library with its Header file as time.h.

The strftime() method is preferred by ANSI C. This method returns the Number of Bytes that enables better Error Control Management if the String is too long to Print. The asctime() method may generate the problem of Buffer Overflow which are managed well in the strftime() method.

The asctime() and asctime_r() methods have, therefore, become obsolete and is, therefore, rarely used by the C Programmers. These methods also do not have Timezone information. This C Program, therefore, fetches the Date and Time into the String and then the String is printed. The struct tm stores the Date and Time. time_t is used to store the Calendar Time in it.

Method 1: C Program To Display Current Date and Time using strftime() method

Method 2: C Code To Print System Date and Time using asctime() method


Display Current Date and Time in C Programming Language

If you have any Doubts or Compilation Errors in this C Program To Display Current Date and Time, let us know about it in the Comment Section below.

Recommended Programs
1C Program For Encryption and Decryption of a Text File
2C Code For Decimal Number To Binary Conversion
3Simple Calculator Application C Program
4Print Map of India in C Programming
5C Program To Print Pascal’s Triangle
6100+ C Programs For Programming Interviews

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

One thought on “Display Current Date and Time C Program

  • August 21, 2016 at 12:17 pm

    Can we make a C Program that automatically updates the date and time?


Join The Discussion