📄 glib-date-and-time-functions.html
字号:
<tr><td><p><span class="term"><em class="parameter"><code>date</code></em> :</span></p></td><td>a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>month</code></em> :</span></p></td><td>month to set</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3037616"></a><h3><a name="g-date-set-year"></a>g_date_set_year ()</h3><a class="indexterm" name="id3037628"></a><pre class="programlisting">void g_date_set_year (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, <a class="link" href="glib-Date-and-Time-Functions.html#GDateYear">GDateYear</a> year);</pre><p>Sets the year for a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a>. If the resulting day-month-year triplet isinvalid, the date will be invalid.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>date</code></em> :</span></p></td><td>a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>year</code></em> :</span></p></td><td>year to set</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3037713"></a><h3><a name="g-date-set-dmy"></a>g_date_set_dmy ()</h3><a class="indexterm" name="id3037726"></a><pre class="programlisting">void g_date_set_dmy (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, <a class="link" href="glib-Date-and-Time-Functions.html#GDateDay">GDateDay</a> day, <a class="link" href="glib-Date-and-Time-Functions.html#GDateMonth">GDateMonth</a> month, <a class="link" href="glib-Date-and-Time-Functions.html#GDateYear">GDateYear</a> y);</pre><p>Sets the value of a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a> from a day, month, and year. The day-month-year triplet must be valid; if you aren't sure it is, call <a class="link" href="glib-Date-and-Time-Functions.html#g-date-valid-dmy"><code class="function">g_date_valid_dmy()</code></a> tocheck before you set it.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>date</code></em> :</span></p></td><td>a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>day</code></em> :</span></p></td><td>day</td></tr><tr><td><p><span class="term"><em class="parameter"><code>month</code></em> :</span></p></td><td>month</td></tr><tr><td><p><span class="term"><em class="parameter"><code>y</code></em> :</span></p></td><td>year</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3037865"></a><h3><a name="g-date-set-julian"></a>g_date_set_julian ()</h3><a class="indexterm" name="id3037878"></a><pre class="programlisting">void g_date_set_julian (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, <a class="link" href="glib-Basic-Types.html#guint32">guint32</a> julian_date);</pre><p>Sets the value of a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a> from a Julian day number.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>date</code></em> :</span></p></td><td>a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>julian_date</code></em> :</span></p></td><td>Julian day number (days since January 1, Year 1)</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3037963"></a><h3><a name="g-date-set-time"></a>g_date_set_time ()</h3><a class="indexterm" name="id3037978"></a><pre class="programlisting">void g_date_set_time (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, <a class="link" href="glib-Date-and-Time-Functions.html#GTime">GTime</a> time_);</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p><code class="literal">g_date_set_time</code> is deprecated and should not be used in newly-written code.</p></div><p>Sets the value of a date from a <a class="link" href="glib-Date-and-Time-Functions.html#GTime"><span class="type">GTime</span></a> value. </p><p><em class="parameter"><code>Deprecated</code></em>:2.10: Use <a class="link" href="glib-Date-and-Time-Functions.html#g-date-set-time-t"><code class="function">g_date_set_time_t()</code></a> instead.</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>date</code></em> :</span></p></td><td> a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>time_</code></em> :</span></p></td><td> <a class="link" href="glib-Date-and-Time-Functions.html#GTime"><span class="type">GTime</span></a> value to set.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3038106"></a><h3><a name="g-date-set-time-t"></a>g_date_set_time_t ()</h3><a class="indexterm" name="id3038121"></a><pre class="programlisting">void g_date_set_time_t (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, time_t timet);</pre><p>Sets the value of a date from a <span class="type">time_t</span> value. </p><p>To set the value of a date to the current day, you could write:</p><div class="informalexample"><pre class="programlisting"> g_date_set_time_t (date, time (NULL)); </pre></div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>date</code></em> :</span></p></td><td> a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a> </td></tr><tr><td><p><span class="term"><em class="parameter"><code>timet</code></em> :</span></p></td><td> <span class="type">time_t</span> value to set</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3038225"></a><h3><a name="g-date-set-time-val"></a>g_date_set_time_val ()</h3><a class="indexterm" name="id3038240"></a><pre class="programlisting">void g_date_set_time_val (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal">GTimeVal</a> *timeval);</pre><p>Sets the value of a date from a <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a> value. Note that the<em class="parameter"><code>tv_usec</code></em> member is ignored, because <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a> can't make use of theadditional precision.</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>date</code></em> :</span></p></td><td> a <a class="link" href="glib-Date-and-Time-Functions.html#GDate"><span class="type">GDate</span></a> </td></tr><tr><td><p><span class="term"><em class="parameter"><code>timeval</code></em> :</span></p></td><td> <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal"><span class="type">GTimeVal</span></a> value to set</td></tr></tbody></table></div><p class="since">Since 2.10</p></div><hr><div class="refsect2" lang="en"><a name="id3038357"></a><h3><a name="g-date-set-parse"></a>g_date_set_parse ()</h3><a class="indexterm" name="id3038370"></a><pre class="programlisting">void g_date_set_parse (<a class="link" href="glib-Date-and-Time-Functions.html#GDate">GDate</a> *date, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *str);</pre><p>Parses a user-inputted string <em class="parameter"><code>str</code></em>, and try to figure out what date itrepresents, taking the <a class="link" href="glib-running.html#setlocale" title="Locale">current locale</a> into account. If the string is successfully parsed, the date will be valid after the call. Otherwise, it will be invalid. You should check using <a class="link" href="glib-Date-and-Time-Functions.html#g-date-valid"><code class="function">g_date_valid()</code></a> to see whether the parsing succeeded.</p><p>This function is not appropriate for file formats and the like; itisn't very precise, and its exact behavior varies with thelocale. It's intended to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -