Write a C program using time.h library function


Problem

How to display the current date and time in ISO standard format using C Programming language?

Solution

The current date and time of the input will be taken and we are trying to print the system time and date in ISO format.

For example, Monday, Dec 15, 2020 10.50p.

The built-in functions that we used in this program are −

Time() − returns current time.

Strftime() − converts the time to string form, this function include in time.h.

Example

 Live Demo

#include<stdio.h>
#include<time.h>
int main(){
   time_t current = time(NULL);
   char datetime[20];
   strftime(datetime,sizeof(datetime),"%a,%d%b%y %H:%M",localtime(¤t));
   puts(datetime);
   return 0;
}

Output

Thu,31 Dec 20 22:41

Updated on: 06-Mar-2021

206 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements