summaryrefslogtreecommitdiff
path: root/devdocs/c/chrono%2Fdifftime.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/chrono%2Fdifftime.html
new repository
Diffstat (limited to 'devdocs/c/chrono%2Fdifftime.html')
-rw-r--r--devdocs/c/chrono%2Fdifftime.html45
1 files changed, 45 insertions, 0 deletions
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 @@
+ <h1 id="firstHeading" class="firstHeading">difftime</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;time.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td class="t-dcl-nopad"> <pre data-language="c">double difftime( time_t time_end, time_t time_beg );</pre>
+</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Computes difference between two calendar times as <code><a href="time_t" title="c/chrono/time t">time_t</a></code> objects (<code>time_end - time_beg</code>) in seconds. If <code>time_end</code> refers to time point before <code>time_beg</code> then the result is negative.</p>
+<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> time_beg, time_end </td> <td> - </td> <td> times to compare </td>
+</tr>
+</table> <h3 id="Return_value"> Return value</h3> <p>Difference between two times in seconds.</p>
+<h3 id="Notes"> Notes</h3> <p>On POSIX systems, <code><a href="time_t" title="c/chrono/time t">time_t</a></code> is measured in seconds, and <code>difftime</code> is equivalent to arithmetic subtraction, but C and C++ allow fractional units for <code><a href="time_t" title="c/chrono/time t">time_t</a></code>.</p>
+<h3 id="Example"> Example</h3> <div class="t-example">
+<p>The following program computes the number of seconds that have passed since the beginning of the month.</p>
+<div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
+#include &lt;time.h&gt;
+
+int main(void)
+{
+ time_t now = time(0);
+
+ struct tm beg = *localtime(&amp;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(&amp;beg));
+
+ printf("%.f seconds have passed since the beginning of the month.\n", seconds);
+
+ return 0;
+}</pre></div> <p>Output:</p>
+<div class="text source-text"><pre data-language="c">1937968 seconds have passed since the beginning of the month.</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul><li> 7.27.2.2 The difftime function (p: 285) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.27.2.2 The difftime function (p: 390) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 7.23.2.2 The difftime function (p: 338) </li></ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 7.12.2.2 The difftime function (p: 171) </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/chrono/c/difftime" title="cpp/chrono/c/difftime">C++ documentation</a></span> for <code>difftime</code> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
+ <a href="https://en.cppreference.com/w/c/chrono/difftime" class="_attribution-link">https://en.cppreference.com/w/c/chrono/difftime</a>
+ </p>
+</div>