
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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
Advertisements