C Program To Output Current Date And Time

C programming language has several predefined macros. In this article we will demonstrate the usage of two important macros.

Before you begin with the example, learn C programming basics. If you know them already, skip and continue with the examples.

Advertisements

Problem Definition

As we mentioned earlier, there are two important macros related to Date and Time. This example program demonstrate the usage of these macros.

__DATE__

The data macro expands to a string constant that display date when the preprocessor was run. It display the date in following format – “ Jan 23 2012 “. If it cannot show the data then, display –  “??? ??  ????“.

Advertisements

__TIME__

The time macro expands to a string that shows the current time when the preprocessor ran on the system. It display the time in following format – “12:55:35“. If date cannot be displayed then it shows –  “??? ??  ????”

Program Source Code

#include <stdio.h>
#include <stdlib.h>
int main()
{
     printf("Current Date: %s\n\n",__DATE__);
     printf("Current Time: %s\n\n",__TIME__);
     system("PAUSE"); 
     return 0;
}

Output

Current Date: Jul 11 2018
Current Time: 22:41:38
Press any key to continue . . ._
Advertisements

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Exit mobile version