summaryrefslogtreecommitdiff
path: root/devdocs/c/chrono%2Ftimespec_get.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%2Ftimespec_get.html
new repository
Diffstat (limited to 'devdocs/c/chrono%2Ftimespec_get.html')
-rw-r--r--devdocs/c/chrono%2Ftimespec_get.html43
1 files changed, 43 insertions, 0 deletions
diff --git a/devdocs/c/chrono%2Ftimespec_get.html b/devdocs/c/chrono%2Ftimespec_get.html
new file mode 100644
index 00000000..ab32e7f2
--- /dev/null
+++ b/devdocs/c/chrono%2Ftimespec_get.html
@@ -0,0 +1,43 @@
+ <h1 id="firstHeading" class="firstHeading">timespec_get</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 t-since-c11"> <td> <pre data-language="c">int timespec_get( struct timespec *ts, int base );</pre>
+</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">#define TIME_UTC /* implementation-defined */</pre>
+</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <div class="t-li1">
+<span class="t-li">1)</span> Modifies the <code>timespec</code> object pointed to by <code>ts</code> to hold the current calendar time in the time base <code>base</code>.</div> <div class="t-li1">
+<span class="t-li">2)</span> Expands to a value suitable for use as the <code>base</code> argument of <code>timespec_get</code>
+</div> <p>Other macro constants beginning with <code>TIME_</code> may be provided by the implementation to indicate additional time bases</p>
+<p>If <code>base</code> is <code>TIME_UTC</code>, then</p>
+<ul>
+<li> <code>ts-&gt;tv_sec</code> is set to the number of seconds since an implementation defined epoch, truncated to a whole value </li>
+<li> <code>ts-&gt;tv_nsec</code> member is set to the integral number of nanoseconds, rounded to the resolution of the system clock </li>
+</ul> <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 successful, 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_gettime(CLOCK_REALTIME, ts)</code></a> may also be used to populate a <code>timespec</code> with the time since the Epoch.</p>
+<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
+#include &lt;time.h&gt;
+
+int main(void)
+{
+ struct timespec ts;
+ timespec_get(&amp;ts, TIME_UTC);
+ char buff[100];
+ strftime(buff, sizeof buff, "%D %T", gmtime(&amp;ts.tv_sec));
+ printf("Current time: %s.%09ld UTC\n", buff, ts.tv_nsec);
+}</pre></div> <p>Possible output:</p>
+<div class="text source-text"><pre data-language="c">Current time: 02/18/15 14:34:03.048508855 UTC</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul><li> 7.27.2.5 The timespec_get function (p: 286) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.27.2.5 The timespec_get function (p: 390) </li></ul>
+</ul> <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_getres" title="c/chrono/timespec getres"> <span class="t-lines"><span>timespec_getres</span></span></a></div>
+<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> returns the resolution of calendar time 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> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/chrono/c/timespec_get" title="cpp/chrono/c/timespec get">C++ documentation</a></span> for <code>timespec_get</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/timespec_get" class="_attribution-link">https://en.cppreference.com/w/c/chrono/timespec_get</a>
+ </p>
+</div>