DateTime
Object Hierarchy:
GLib.DateTime
GLib.DateTime
GLib.DateTime
Description:
[ Compact ] [ Version ( since = "2.26" ) ] [ CCode ( ref_function = "g_date_time_ref" , type_id = "G_TYPE_DATE_TIME" , unref_function = "g_date_time_unref" ) ]public class DateTime
`GDateTime` is a structure that combines a Gregorian date and time into a single structure.
`GDateTime` provides many conversion and methods to manipulate dates and times. Time precision is provided down to microseconds and the time
can range (proleptically) from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999. `GDateTime` follows POSIX time in the sense that it is
oblivious to leap seconds.
`GDateTime` is an immutable object; once it has been created it cannot be modified further. All modifiers will create a new `GDateTime`. Nearly
all such functions can fail due to the date or time going out of range, in which case null will be returned.
`GDateTime` is reference counted: the reference count is increased by calling [method@GLib.DateTime.ref] and decreased by calling [
method@GLib.DateTime.unref]. When the reference count drops to 0, the resources allocated by the `GDateTime` structure are released.
Many parts of the API may produce non-obvious results. As an example, adding two months to January 31st will yield March 31st whereas adding
one month and then one month again will yield either March 28th or March 29th. Also note that adding 24 hours is not always the same as adding
one day (since days containing daylight savings time transitions are either 23 or 25 hours in length).
Content:
Creation methods:
public DateTime (TimeZone tz, int year, int month, int day, int hour, int minute, double seconds)
Creates a new DateTime corresponding to the given
date and time in the time zone tz
.
public DateTime.from_iso8601 (string text, TimeZone ? default_tz)
public DateTime.from_timeval_local (TimeVal tv)
Creates a DateTime corresponding to the given
TimeVal tv
in the local time zone.
public DateTime.from_timeval_utc (TimeVal tv)
Creates a DateTime corresponding to the given
TimeVal tv
in UTC.
public DateTime.from_unix_local (int64 t)
Creates a DateTime corresponding to the given
Unix time t
in the local time zone.
public DateTime.from_unix_utc (int64 t)
Creates a DateTime corresponding to the given
Unix time t
in UTC.
public DateTime.local (int year, int month, int day, int hour, int minute, double seconds)
Creates a new DateTime corresponding to the given
date and time in the local time zone.
public DateTime.now (TimeZone tz = new TimeZone.local ())
Creates a DateTime corresponding to this exact
instant in the given time zone tz
.
public DateTime.now_local ()
Creates a DateTime corresponding to this exact
instant in the local time zone.
public DateTime.now_utc ()
Creates a DateTime corresponding to this exact
instant in UTC.
public DateTime.utc (int year, int month, int day, int hour, int minute, double seconds)
Creates a new DateTime corresponding to the given
date and time in UTC.
Methods:
public DateTime add (TimeSpan timespan)
Creates a copy of this and adds the
specified timespan to the copy.
public DateTime add_days (int days)
Creates a copy of this and adds the
specified number of days to the copy.
public DateTime add_full (int years, int months, int days, int hours = 0 , int minutes = 0 , double seconds = 0 )
Creates a new DateTime adding the specified
values to the current date and time in this .
public DateTime add_hours (int hours)
Creates a copy of this and adds the
specified number of hours.
public DateTime add_minutes (int minutes)
Creates a copy of this adding the
specified number of minutes.
public DateTime add_months (int months)
Creates a copy of this and adds the
specified number of months to the copy.
public DateTime add_seconds (double seconds)
Creates a copy of this and adds the
specified number of seconds.
public DateTime add_weeks (int weeks)
Creates a copy of this and adds the
specified number of weeks to the copy.
public DateTime add_years (int years)
Creates a copy of this and adds the
specified number of years to the copy.
public int compare (DateTime dt)
A comparison function for DateTime s that is
suitable as a SearchFunc .
public TimeSpan difference (DateTime begin)
Calculates the difference in time between this
and begin
.
public bool equal (DateTime dt)
Checks to see if this and dt2
are equal.
public string format (string format)
Creates a newly allocated string representing the requested format
.
public string format_iso8601 ()
Format this in
ISO 8601 format , including the date, time and time zone, and return
that as a UTF-8 encoded string.
public int get_day_of_month ()
Retrieves the day of the month represented by
this in the gregorian calendar.
public int get_day_of_week ()
Retrieves the ISO 8601 day of the week on which
this falls (1 is Monday, 2 is Tuesday... 7 is Sunday).
public int get_day_of_year ()
Retrieves the day of the year represented by this
in the Gregorian calendar.
public int get_hour ()
Retrieves the hour of the day represented by this
public int get_microsecond ()
Retrieves the microsecond of the date represented by
this
public int get_minute ()
Retrieves the minute of the hour represented by
this
public int get_month ()
Retrieves the month of the year represented by
this in the Gregorian calendar.
public int get_second ()
Retrieves the second of the minute represented by
this
public double get_seconds ()
Retrieves the number of seconds since the start of the last minute,
including the fractional part.
public unowned TimeZone get_timezone ()
Get the time zone for this this .
public unowned string get_timezone_abbreviation ()
Determines the time zone abbreviation to be used at the time and in the time
zone of this .
public TimeSpan get_utc_offset ()
Determines the offset to UTC in effect at the time and in the time zone of
this .
public int get_week_numbering_year ()
Returns the ISO 8601 week-numbering year in which the week containing
this falls.
public int get_week_of_year ()
Returns the ISO 8601 week number for the week containing
this .
public int get_year ()
Retrieves the year represented by this in
the Gregorian calendar.
public void get_ymd (out int year, out int month, out int day)
Retrieves the Gregorian day, month, and year of a given
DateTime .
public uint hash ()
public bool is_daylight_savings ()
Determines if daylight savings time is in effect at the time and in the time
zone of this .
public DateTime to_local ()
Creates a new DateTime corresponding to the same
instant in time as this , but in the local time zone.
public string to_string ()
Converts the value to its equivalent string representation
public bool to_timeval (out TimeVal tv)
Stores the instant in time that this
represents into tv
.
public DateTime to_timezone (TimeZone tz)
Create a new DateTime corresponding to the same
instant in time as this , but in the time zone tz
.
public int64 to_unix ()
Gives the Unix time corresponding to this ,
rounding down to the nearest second.
public DateTime to_utc ()
Creates a new DateTime corresponding to the same
instant in time as this , but in UTC.