Write a C program using time.h library function

CServer Side ProgrammingProgramming

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
raja
Published on 06-Mar-2021 12:23:56
Advertisements