From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/chrono%2Fdifftime.html | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 devdocs/c/chrono%2Fdifftime.html (limited to 'devdocs/c/chrono%2Fdifftime.html') diff --git a/devdocs/c/chrono%2Fdifftime.html b/devdocs/c/chrono%2Fdifftime.html new file mode 100644 index 00000000..d72402bb --- /dev/null +++ b/devdocs/c/chrono%2Fdifftime.html @@ -0,0 +1,45 @@ +

difftime

Defined in header <time.h>
double difftime( time_t time_end, time_t time_beg );
+

Computes difference between two calendar times as time_t objects (time_end - time_beg) in seconds. If time_end refers to time point before time_beg then the result is negative.

+

Parameters

+ +
time_beg, time_end - times to compare

Return value

Difference between two times in seconds.

+

Notes

On POSIX systems, time_t is measured in seconds, and difftime is equivalent to arithmetic subtraction, but C and C++ allow fractional units for time_t.

+

Example

+

The following program computes the number of seconds that have passed since the beginning of the month.

+
#include <stdio.h>
+#include <time.h>
+ 
+int main(void)
+{
+    time_t now = time(0);
+ 
+    struct tm beg = *localtime(&now);
+ 
+    // set beg to the beginning of the month
+    beg.tm_hour = 0,
+    beg.tm_min = 0,
+    beg.tm_sec = 0,
+    beg.tm_mday = 1;
+ 
+    double seconds = difftime(now, mktime(&beg));
+ 
+    printf("%.f seconds have passed since the beginning of the month.\n", seconds);
+ 
+    return 0;
+}

Output:

+
1937968 seconds have passed since the beginning of the month.

References

See also

+
C++ documentation for difftime
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/chrono/difftime +

+
-- cgit v1.2.3