Home  >  Article  >  Backend Development  >  Write a C program that uses time.h library functions

Write a C program that uses time.h library functions

WBOY
WBOYforward
2023-09-15 23:01:02624browse

Write a C program that uses time.h library functions

Question

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

Solution

Current Date and Time will take the entered time and attempt to print the system time and date in ISO format.

For example, Monday, December 15, 2020 at 10:50.

Built - The function we are using in this program is -

Time() - Returns the current time.

Strftime() − Convert time to string form, this function is included in time.h.

Example

Live demonstration

#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(&curren;t));
   puts(datetime);
   return 0;
}

Output

Thu,31 Dec 20 22:41

The above is the detailed content of Write a C program that uses time.h library functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete