

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Difftime() C library function
Here we will see what is the difftime() function in C. The difftime() is used to get the differences between two time values.
difftime() takes two time argument, the first one is the lower bound, and the second one is the upper bound. And it returns the differences between these two arguments.
Example
#include <time.h> #include <stdio.h> #include <unistd.h> main() { int sec; time_t time1, time2; time(&time1); printf("Current Time: %ld\n",time1); for (sec = 1; sec <= 5; sec++){ sleep(1); printf("Count: %d\n",sec); } time(&time2); printf("Ending Time: %ld\n",time2); printf("Difference is %.2f seconds", difftime(time2, time1)); }
Output
Current Time: 1554918635 Count: 1 Count: 2 Count: 3 Count: 4 Count: 5 Ending Time: 1554918640 Difference is 5.00 seconds
- Related Questions & Answers
- difftime() function in C++
- isgraph() C library function
- Write a C program demonstrating strlen library function
- Write a C program using time.h library function
- How to call a jQuery library function?
- Chrono library in C++
- Library in C++ STL?
- Write a C program to compare two strings using strncmp library function
- Write a C program to Reverse a string without using a library function
- C++ Standard Library Header Files
- Advanced C++ with boost library
- The C++ Standard Template Library (STL)
- Any datatype in C++ boost library
- wprintf() and wscanf in C Library
- What are the C library functions?
Advertisements