📄 glib-date-and-time-functions.html
字号:
</div><hr><div class="refsect2" lang="en"><a name="id3035090"></a><h3><a name="GTimeVal"></a>GTimeVal</h3><a class="indexterm" name="id3035102"></a><pre class="programlisting">typedef struct { glong tv_sec; glong tv_usec;} GTimeVal;</pre><p>Represents a precise time, with seconds and microseconds. Similar to the <span class="structname">struct timeval</span> returned by the <code class="function"><code class="function">gettimeofday()</code></code> UNIX call.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#glong">glong</a> <em class="structfield"><code>tv_sec</code></em>;</span></p></td><td>seconds</td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#glong">glong</a> <em class="structfield"><code>tv_usec</code></em>;</span></p></td><td>microseconds</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3035183"></a><h3><a name="g-get-current-time"></a>g_get_current_time ()</h3><a class="indexterm" name="id3035196"></a><pre class="programlisting">void g_get_current_time (<a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal">GTimeVal</a> *result);</pre><p>Equivalent to the UNIX <code class="function">gettimeofday()</code> function, but portable.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>result</code></em> :</span></p></td><td> <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a> structure in which to store current time.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3035265"></a><h3><a name="g-usleep"></a>g_usleep ()</h3><a class="indexterm" name="id3035277"></a><pre class="programlisting">void g_usleep (<a class="link" href="glib-Basic-Types.html#gulong">gulong</a> microseconds);</pre><p>Pauses the current thread for the given number of microseconds. Thereare 1 million microseconds per second (represented by the<a class="link" href="glib-Date-and-Time-Functions.html#G-USEC-PER-SEC:CAPS"><span class="type">G_USEC_PER_SEC</span></a> macro). <a class="link" href="glib-Date-and-Time-Functions.html#g-usleep"><code class="function">g_usleep()</code></a> may have limited precision,depending on hardware and operating system; don't rely on the exactlength of the sleep.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>microseconds</code></em> :</span></p></td><td>number of microseconds to pause</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3035347"></a><h3><a name="g-time-val-add"></a>g_time_val_add ()</h3><a class="indexterm" name="id3035360"></a><pre class="programlisting">void g_time_val_add (<a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal">GTimeVal</a> *time_, <a class="link" href="glib-Basic-Types.html#glong">glong</a> microseconds);</pre><p>Adds the given number of microseconds to <em class="parameter"><code>time_</code></em>. <em class="parameter"><code>microseconds</code></em> canalso be negative to decrease the value of <em class="parameter"><code>time_</code></em>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>time_</code></em> :</span></p></td><td> a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>microseconds</code></em> :</span></p></td><td> number of microseconds to add to <em class="parameter"><code>time</code></em></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3035464"></a><h3><a name="g-time-val-from-iso8601"></a>g_time_val_from_iso8601 ()</h3><a class="indexterm" name="id3035479"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> g_time_val_from_iso8601 (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *iso_date, <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal">GTimeVal</a> *time_);</pre><p>Converts a string containing an ISO 8601 encoded date and timeto a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a> and puts it into <em class="parameter"><code>time_</code></em>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>iso_date</code></em> :</span></p></td><td> a ISO 8601 encoded date string</td></tr><tr><td><p><span class="term"><em class="parameter"><code>time_</code></em> :</span></p></td><td> a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the conversion was successful.</td></tr></tbody></table></div><p class="since">Since 2.12</p></div><hr><div class="refsect2" lang="en"><a name="id3035602"></a><h3><a name="g-time-val-to-iso8601"></a>g_time_val_to_iso8601 ()</h3><a class="indexterm" name="id3035617"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* g_time_val_to_iso8601 (<a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal">GTimeVal</a> *time_);</pre><p>Converts <em class="parameter"><code>time_</code></em> into a ISO 8601 encoded string, relative to theCoordinated Universal Time (UTC).</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>time_</code></em> :</span></p></td><td> a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> a newly allocated string containing a ISO 8601 date</td></tr></tbody></table></div><p class="since">Since 2.12</p></div><hr><div class="refsect2" lang="en"><a name="id3035700"></a><h3><a name="GDate"></a>GDate</h3><a class="indexterm" name="id3035712"></a><pre class="programlisting">typedef struct { guint julian_days : 32; /* julian days representation - we use a * bitfield hoping that 64 bit platforms * will pack this whole struct in one big * int */ guint julian : 1; /* julian is valid */ guint dmy : 1; /* dmy is valid */ /* DMY representation */ guint day : 6; guint month : 4; guint year : 16;} GDate;</pre><p>Represents a day between January 1, Year 1 and a few thousand years inthe future. None of its members should be accessed directly. If the<span class="structname">GDate</span> is obtained from <a class="link" href="glib-Date-and-Time-Functions.html#g-date-new"><code class="function">g_date_new()</code></a>, it willbe safe to mutate but invalid and thus not safe for calendrical computations.If it's declared on the stack, it will contain garbage so must beinitialized with <a class="link" href="glib-Date-and-Time-Functions.html#g-date-clear"><code class="function">g_date_clear()</code></a>. <a class="link" href="glib-Date-and-Time-Functions.html#g-date-clear"><code class="function">g_date_clear()</code></a> makes the date invalidbut sane. An invalid date doesn't represent a day, it's "empty." Adate becomes valid after you set it to a Julian day or you set a day,month, and year.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>julian_days</code></em> : 32;</span></p></td><td>the Julian representation of the date</td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>julian</code></em> : 1;</span></p></td><td>this bit is set if <em class="parameter"><code>julian_days</code></em> is valid</td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>dmy</code></em> : 1;</span></p></td><td>this is set if <em class="parameter"><code>day</code></em>, <em class="parameter"><code>month</code></em> and <em class="parameter"><code>year</code></em> are valid</td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>day</code></em> : 6;</span></p></td><td>the day of the day-month-year representation of the date, as a number between 1 and 31</td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>month</code></em> : 4;</span></p></td><td>the day of the day-month-year representation of the date, as a number between 1 and 12</td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>year</code></em> : 16;</span></p></td><td>the day of the day-month-year representation of the date</td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -