diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/chrono%2Ftimespec_getres.html | |
new repository
Diffstat (limited to 'devdocs/c/chrono%2Ftimespec_getres.html')
| -rw-r--r-- | devdocs/c/chrono%2Ftimespec_getres.html | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/devdocs/c/chrono%2Ftimespec_getres.html b/devdocs/c/chrono%2Ftimespec_getres.html new file mode 100644 index 00000000..b40a3243 --- /dev/null +++ b/devdocs/c/chrono%2Ftimespec_getres.html @@ -0,0 +1,34 @@ + <h1 id="firstHeading" class="firstHeading">timespec_getres</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><time.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">int timespec_getres( struct timespec *ts, int base );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> </table> <p>If <code>ts</code> is non-null and <code>base</code> is supported by <code>timespec_get</code>, modifies <code>*ts</code> to hold the resolution of time provided by <code>timespec_get</code> for <code>base</code>. For each supported <code>base</code>, multiple calls to <code>timespec_getres</code> during the same program execution have identical results.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> ts </td> <td> - </td> <td> pointer to an object of type <code>struct timespec</code> </td> +</tr> <tr class="t-par"> <td> base </td> <td> - </td> <td> <code>TIME_UTC</code> or another nonzero integer value indicating the time base </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>The value of <code>base</code> if <code>base</code> is supported, zero otherwise.</p> +<h3 id="Notes"> Notes</h3> <p>The POSIX function <a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html"><code>clock_getres(clock_id, ts)</code></a> may also be used to populate a <code>timespec</code> with the resolution of time identified by <code>clock_id</code>.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <time.h> + +int main(void) +{ + char buff[128]; + struct timespec ts; + const int res = timespec_getres(&ts, TIME_UTC); + if (res == TIME_UTC) { + struct tm timer; + strftime(buff, sizeof buff, "%D %T", gmtime_r(&ts.tv_sec, &timer)); + printf("Time resolution info: %s.%09ld UTC\n", buff, ts.tv_nsec); + } else { + printf("TIME_UTC base is not supported."); + } +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Time resolution info: 01/01/70 00:00:00.000000001 UTC</pre></div> </div> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="timespec" title="c/chrono/timespec"> <span class="t-lines"><span>timespec</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> time in seconds and nanoseconds <br><span class="t-mark">(struct)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="timespec_get" title="c/chrono/timespec get"> <span class="t-lines"><span>timespec_get</span></span></a></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> returns the calendar time in seconds and nanoseconds based on a given time base <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="time" title="c/chrono/time"> <span class="t-lines"><span>time</span></span></a></div> </td> <td> returns the current calendar time of the system as time since epoch <br> <span class="t-mark">(function)</span> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/chrono/timespec_getres" class="_attribution-link">https://en.cppreference.com/w/c/chrono/timespec_getres</a> + </p> +</div> |
