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

Write a C program that uses time.h library functions

WBOY
Release: 2023-09-15 23:01:02
forward
636 people have browsed it

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;
}
Copy after login

Output

Thu,31 Dec 20 22:41
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template