Home C# Display the current Date and Time in C

Display the current Date and Time in C

In this example we show you how to display the current date and time in C

We will include the time library and then use the function char *ctime(const time_t *timer) which returns a string representing the localtime.

The returned string has the following format: Www Mmm dd hh:mm:ss yyyy.

Www is the weekday
Mmm the month in 3 character letter format e.g Apr
dd is the day of the month
hh:mm:ss is the time in hours, minutes and seconds
yyyy is the year.



int main()
    time_t theTime;   // not a primitive datatype

    printf("\nThe date and time is : %s", ctime(&theTime));

    return 0;


When I ranĀ  this I saw the following

The date and time is : Mon Apr 18 17:41:55 2022

You may also like