C Program to Display the current Date and Time

The C library function char *ctime(const time_t *timer) returns a string representing the localtime based on the argument timer. The returned string has the following format: Www Mmm dd hh:mm:ss yyyy. Here Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time and yyyy the year.

Below is the program to display current date and time.

#include<time.h> is used for time and ctime function and time_t datatype.

#include<stdio.h>
#include<time.h>

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");

    time_t t;   // not a primitive datatype
    time(&t);

    printf("\nThis program has been writeen at (date and time): %s", ctime(&t));

    printf("\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}

Output:

c program out to Display current date and time