Print today's date in C

This is an example C program illustrating the use of time, localtime_r, and strftime to print today's date.

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

#define SIZE 0x100

int main ()
{
    time_t t;
    char buffer[SIZE];
    struct tm ltime;

    t = time (0);
    localtime_r (& t, & ltime);
    
    strftime (buffer, SIZE, "%A, %e of %B %Y", & ltime);
    printf ("Today is %s.\n", buffer);

    return 0;
}

(download)

The output of the example looks like this:

Today is Monday, 22 of August 2016.


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer