- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- difftime() function in C++
- isgraph() C library function
- Write a C program using time.h library function
- Write a C program demonstrating strlen library function
- Write a C program to compare two strings using strncmp library function
- How to call a jQuery library function?
- Write a C program to Reverse a string without using a library function
- Chrono library in C++
- Library in C++ STL?
- Swift Program to Find Largest Set Element Using Library Function
- Swift Program to Find Minimum Set Element Using Library Function
- Advanced C++ with boost library
- C++ Standard Library Header Files
- Converting number of corresponding string without using library function in JavaScript
- How to avoid jQuery function conflict with any other JavaScript library

Advertisements