⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 date.sgml

📁 This GLib version 2.16.1. GLib is the low-level core library that forms the basis for projects such
💻 SGML
📖 第 1 页 / 共 2 页
字号:
<!-- ##### SECTION Title ##### -->Date and Time Functions<!-- ##### SECTION Short_Description ##### -->calendrical calculations and miscellaneous time stuff<!-- ##### SECTION Long_Description ##### --><para>The #GDate data structure represents a day between January 1, Year 1,and sometime a few thousand years in the future (right now it will goto the year 65535 or so, but g_date_set_parse() only parses up to theyear 8000 or so - just count on "a few thousand"). #GDate is meant torepresent everyday dates, not astronomical dates or historical datesor ISO timestamps or the like. It extrapolates the current Gregoriancalendar forward and backward in time; there is no attempt to changethe calendar to match time periods or locations. #GDate does not storetime information; it represents a <emphasis>day</emphasis>.</para><para>The #GDate implementation has several nice features; it is only a64-bit struct, so storing large numbers of dates is very efficient. Itcan keep both a Julian and day-month-year representation of the date,since some calculations are much easier with one representation or theother. A Julian representation is simply a count of days since somefixed day in the past; for #GDate the fixed day is January 1, 1 AD.("Julian" dates in the #GDate API aren't really Julian dates in thetechnical sense; technically, Julian dates count from the start of theJulian period, Jan 1, 4713 BC).</para><para>#GDate is simple to use. First you need a "blank" date; you can get adynamically allocated date from g_date_new(), or you can declare anautomatic variable or array and initialize it to a sane state bycalling g_date_clear(). A cleared date is sane; it's safe to callg_date_set_dmy() and the other mutator functions to initialize thevalue of a cleared date. However, a cleared date is initially<emphasis>invalid</emphasis>, meaning that it doesn't represent a daythat exists. It is undefined to call any of the date calculationroutines on an invalid date. If you obtain a date from a user or otherunpredictable source, you should check its validity with theg_date_valid() predicate. g_date_valid() is also used to check forerrors with g_date_set_parse() and other functions that canfail. Dates can be invalidated by calling g_date_clear() again.</para><para><emphasis>It is very important to use the API to access the #GDatestruct.</emphasis> Often only the day-month-year or only the Julianrepresentation is valid. Sometimes neither is valid. Use the API.</para><para>GLib doesn't contain any time-manipulation functions; however, thereis a #GTime typedef and a #GTimeVal struct which represents a more precise time (with microseconds). You can request the current time as a #GTimeVal with g_get_current_time().</para><!-- ##### SECTION See_Also ##### --><para></para><!-- ##### SECTION Stability_Level ##### --><!-- ##### MACRO G_USEC_PER_SEC ##### --><para>Number of microseconds in one second (1 million). This macro is provided forcode readability.</para><!-- ##### STRUCT GTimeVal ##### --><para>Represents a precise time, with seconds and microseconds. Similar to the <structname>struct timeval</structname> returned by the <function>gettimeofday()</function> UNIX call.</para>@tv_sec: seconds@tv_usec: microseconds<!-- ##### FUNCTION g_get_current_time ##### --><para></para>@result: <!-- ##### FUNCTION g_usleep ##### --><para>Pauses the current thread for the given number of microseconds. Thereare 1 million microseconds per second (represented by the#G_USEC_PER_SEC macro). g_usleep() may have limited precision,depending on hardware and operating system; don't rely on the exactlength of the sleep.</para>@microseconds: number of microseconds to pause<!-- ##### FUNCTION g_time_val_add ##### --><para></para>@time_: @microseconds: <!-- ##### FUNCTION g_time_val_from_iso8601 ##### --><para></para>@iso_date: @time_: @Returns: <!-- ##### FUNCTION g_time_val_to_iso8601 ##### --><para></para>@time_: @Returns: <!-- ##### STRUCT GDate ##### --><para>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<structname>GDate</structname> is obtained from g_date_new(), 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 g_date_clear(). g_date_clear() 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.</para>@julian_days: the Julian representation of the date@julian: this bit is set if @julian_days is valid@dmy: this is set if @day, @month and @year are valid@day: the day of the day-month-year representation of the date, as   a number between 1 and 31@month: the day of the day-month-year representation of the date, as   a number between 1 and 12@year: the day of the day-month-year representation of the date<!-- ##### TYPEDEF GTime ##### --><para>Simply a replacement for <type>time_t</type>. It has been deprectedsince it is <emphasis>not</emphasis> equivalent to <type>time_t</type> on 64-bit platforms with a 64-bit <type>time_t</type>. Unrelated to #GTimer.</para><para>Note that <type>GTime</type> is defined to always be a 32bit integer,unlike <type>time_t</type> which may be 64bit on some systems. Therefore, <type>GTime</type> will overflow in the year 2038, andyou cannot use the address of a <type>GTime</type> variable as argument to the UNIX time() function. Instead, do the following:<informalexample><programlisting>time_t ttime;GTime gtime;time (&amp;ttime);gtime = (GTime)ttime;</programlisting></informalexample></para><!-- ##### ENUM GDateDMY ##### --><para>This enumeration isn't used in the API, but may be useful if you needto mark a number as a day, month, or year.</para>@G_DATE_DAY: a day@G_DATE_MONTH: a month@G_DATE_YEAR: a year<!-- ##### TYPEDEF GDateDay ##### --><para>Integer representing a day of the month; between 1 and31. #G_DATE_BAD_DAY represents an invalid day of the month.</para><!-- ##### ENUM GDateMonth ##### --><para>Enumeration representing a month; values are #G_DATE_JANUARY,#G_DATE_FEBRUARY, etc. #G_DATE_BAD_MONTH is the invalid value.</para>@G_DATE_BAD_MONTH: invalid value@G_DATE_JANUARY: January@G_DATE_FEBRUARY: February@G_DATE_MARCH: March@G_DATE_APRIL: April@G_DATE_MAY: May@G_DATE_JUNE: June@G_DATE_JULY: July@G_DATE_AUGUST: August@G_DATE_SEPTEMBER: September@G_DATE_OCTOBER: October@G_DATE_NOVEMBER: November@G_DATE_DECEMBER: December<!-- ##### TYPEDEF GDateYear ##### --><para>Integer representing a year; #G_DATE_BAD_YEAR is the invalidvalue. The year must be 1 or higher; negative (BC) years are notallowed. The year is represented with four digits.</para><!-- ##### ENUM GDateWeekday ##### --><para>Enumeration representing a day of the week; #G_DATE_MONDAY,#G_DATE_TUESDAY, etc. #G_DATE_BAD_WEEKDAY is an invalid weekday.</para>@G_DATE_BAD_WEEKDAY: invalid value@G_DATE_MONDAY: Monday@G_DATE_TUESDAY: Tuesday@G_DATE_WEDNESDAY: Wednesday@G_DATE_THURSDAY: Thursday@G_DATE_FRIDAY: Friday@G_DATE_SATURDAY: Saturday@G_DATE_SUNDAY: Sunday<!-- ##### MACRO G_DATE_BAD_DAY ##### --><para>Represents an invalid #GDateDay.</para><!-- ##### MACRO G_DATE_BAD_JULIAN ##### --><para>Represents an invalid Julian day number.</para><!-- ##### MACRO G_DATE_BAD_YEAR ##### --><para>Represents an invalid year.</para><!-- ##### FUNCTION g_date_new ##### --><para>Allocates a #GDate and initializes it to a sane state. The new date willbe cleared (as if you'd called g_date_clear()) but invalid (it won'trepresent an existing day). Free the return value with g_date_free().</para>@Returns: a newly-allocated #GDate<!-- ##### FUNCTION g_date_new_dmy ##### --><para>Like g_date_new(), but also sets the value of the date. Assuming theday-month-year triplet you pass in represents an existing day, thereturned date will be valid.</para>@day: day of the month@month: month of the year@year: year@Returns: a newly-allocated #GDate initialized with @day, @month, and @year<!-- ##### FUNCTION g_date_new_julian ##### --><para>Like g_date_new(), but also sets the value of the date. Assuming theJulian day number you pass in is valid (greater than 0, less than anunreasonably large number), the returned date will be valid.</para>@julian_day: days since January 1, Year 1@Returns: a newly-allocated #GDate initialized with @julian_day<!-- ##### FUNCTION g_date_clear ##### --><para>Initializes one or more #GDate structs to a sane but invalidstate. The cleared dates will not represent an existing date, but willnot contain garbage. Useful to init a date declared on the stack.Validity can be tested with g_date_valid().</para>@date: pointer to one or more dates to clear@n_dates: number of dates to clear<!-- ##### FUNCTION g_date_free ##### --><para>Frees a #GDate returned from g_date_new().</para>@date: a #GDate<!-- ##### FUNCTION g_date_set_day ##### --><para>Sets the day of the month for a #GDate. If the resulting day-month-yeartriplet is invalid, the date will be invalid.</para>@date: a #GDate@day: day to set<!-- ##### FUNCTION g_date_set_month ##### --><para>Sets the month of the year for a #GDate.  If the resultingday-month-year triplet is invalid, the date will be invalid.</para>@date: a #GDate@month: month to set<!-- ##### FUNCTION g_date_set_year ##### --><para>Sets the year for a #GDate. If the resulting day-month-year triplet isinvalid, the date will be invalid.</para>@date: a #GDate@year: year to set<!-- ##### FUNCTION g_date_set_dmy ##### --><para>Sets the value of a #GDate from a day, month, and year. The day-month-year triplet must be valid; if you aren't sure it is, call g_date_valid_dmy() tocheck before you set it.</para>@date: a #GDate@day: day@month: month@y: year<!-- ##### FUNCTION g_date_set_julian ##### --><para>Sets the value of a #GDate from a Julian day number.</para>@date: a #GDate@julian_date: Julian day number (days since January 1, Year 1)<!-- ##### FUNCTION g_date_set_time ##### --><para></para>@date: @time_: <!-- ##### FUNCTION g_date_set_time_t ##### --><para></para>@date: @timet: <!-- ##### FUNCTION g_date_set_time_val ##### --><para></para>@date: @timeval: <!-- ##### FUNCTION g_date_set_parse ##### --><para>Parses a user-inputted string @str, and try to figure out what date it

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -