wx.DateTime

Inheritance diagram for wx.DateTime:



Description

wx.DateTime class represents an absolute moment in the time.

Class API

Methods

__init__()
No docstrings available for this method.

AddDS(diff)

Adds the wx.DateSpan diff to self.

Parameters:


Returns:

wx.DateTime


AddTS(diff)

Adds the wx.TimeSpan diff to self.

Parameters:


Returns:

wx.DateTime


ConvertYearToBC(year)

Converts the year in absolute notation (i.e. a number which can be negative, positive or zero) to the year in BC/AD notation. For the positive years, nothing is done, but the year 0 is year 1 BC and so for other years there is a difference of 1.

Parameters:

  • year (int)

Returns:

int


Format(format=wx.DefaultDateTimeFormat, tz=wx.DateTime.Local)

This function does the same as the standard ANSI C strftime(3) function. Please see its description for the meaning of format parameter.

Parameters:

  • format (string)
  • tz (int)

Returns:

string

See also

ParseFormat


FormatDate()

Identical to calling Format with "%x" argument (which means ‘preferred date representation for the current locale’).


Returns:

string


FormatISODate()

This function returns the date representation in the ISO 8601 format (YYYY-MM-DD).


Returns:

string


FormatISOTime()

This function returns the time representation in the ISO 8601 format (HH:MM:SS).


Returns:

string


FormatTime()

Identical to calling Format with "%X" argument (which means ‘preferred time representation for the current locale’).


Returns:

string


FromTimezone(tz, noDST=False)

Transform the date from the given time zone to the local one. If noDST is True, no DST adjustments will be made.

Returns the date in the local time zone.

Parameters:

  • tz (int)
  • noDST (bool)

Returns:

wx.DateTime


FromUTC(noDST=False)

Parameters:

  • noDST (bool)

Returns:

wx.DateTime


GetAmPmStrings()

Returns the translations of the strings AM and PM used for time formatting for the current locale. Either of the pointers may be None if the corresponding value is not needed.


Returns:

(am, pm)


GetBeginDST(year=wx.DateTime.Inv_Year, country=wx.DateTime.Country_Default)

Get the beginning of DST for the given country in the given year (current one by default).

Parameters:

  • year (int)
  • country (int)

Returns:

wx.DateTime

See also

GetEndDST


GetCentury(tz=wx.DateTime.Local)

Returns the century of this date.

Parameters:

  • tz (int)

Returns:

int


GetCountry()

Returns the current default country. The default country is used for DST calculations, for example.


Returns:

int

See also

SetCountry


GetCurrentMonth(cal=wx.DateTime.Gregorian)

Get the current month in given calendar (only Gregorian is currently supported).

Parameters:

  • cal (int)

Returns:

int


GetCurrentYear(cal=wx.DateTime.Gregorian)

Get the current year in given calendar (only Gregorian is currently supported).

Parameters:

  • cal (int)

Returns:

int


GetDateOnly()

Returns the object having the same date component as this one but time of 00:00:00.

This function is new since wxWidgets version 2.8.2


Returns:

wx.DateTime

See also

ResetTime


GetDay()

Returns the day in the given timezone (local one by default).


Returns:

int


GetDayOfYear()

Returns the day of the year (in 1...366 range) in the given timezone (local one by default).


Returns:

int


GetEndDST(year=wx.DateTime.Inv_Year, country=wx.DateTime.Country_Default)

Returns the end of DST for the given country in the given year (current one by default).

Parameters:

  • year (int)
  • country (int)

Returns:

wx.DateTime

See also

GetBeginDST


GetHour()

Returns the hour in the given timezone (local one by default).


Returns:

int


GetJDN()

Synonym for GetJulianDayNumber.


Returns:

double


GetJulianDayNumber()

Returns the JDN corresponding to this date.


Returns:

double

Warning

Beware of rounding errors!


GetLastMonthDay(month=wx.DateTime.Inv_Month, year=wx.DateTime.Inv_Year)

Returns the copy of this object to which SetToLastMonthDay was applied.

Parameters:

  • month (int)
  • year (int)

Returns:

wx.DateTime


GetLastWeekDay(weekday, month=wx.DateTime.Inv_Month, year=wx.DateTime.Inv_Year)

Returns the copy of this object to which SetToLastWeekDay was applied.

Parameters:

  • weekday (int)
  • month (int)
  • year (int)

Returns:

wx.DateTime


GetMJD()

Synonym for GetModifiedJulianDayNumber.


Returns:

double


GetMillisecond()

Returns the milliseconds in the given timezone (local one by default).


Returns:

int


GetMinute()

Returns the minute in the given timezone (local one by default).


Returns:

int


GetModifiedJulianDayNumber()

Returns the Modified Julian Day Number (MJD) which is, by definition, equal to JDN - 2400000.5.

The MJDs are simpler to work with as the integral MJDs correspond to midnights of the dates in the Gregorian calendar and not th noons like JDN. The MJD 0 is Nov 17, 1858.


Returns:

double


GetMonth()

Returns the month in the given timezone (local one by default).


Returns:

int


GetMonthName(month, flag=wx.DateTime.Name_Full)

Gets the full (default) or abbreviated (specify wx.DateTime.Name_Abbr name of the given month.

Parameters:

  • month (int)
  • flag (int)

Returns:

string

See also

GetWeekDayName


GetNextWeekDay(weekday)

Returns the copy of this object to which SetToNextWeekDay was applied.

Parameters:

  • weekday (int)

Returns:

wx.DateTime


GetNumberOfDaysInMonth(month, year=wx.DateTime.Inv_Year, cal=wx.DateTime.Gregorian)

Returns the number of days in the given month of the given year, using the specified calendar.

Parameters:

  • month (int)
  • year (int)
  • cal (int)

Returns:

int


GetNumberOfDaysInYear(year, cal=wx.DateTime.Gregorian)

Returns the number of days in the given year, using the specified calendar.

Parameters:

  • year (int)
  • cal (int)

Returns:

int


GetPrevWeekDay(weekday)

Returns the copy of this object to which SetToPrevWeekDay was applied.

Parameters:

  • weekday (int)

Returns:

wx.DateTime


GetRataDie()

Return the Rata Die number of this date.

By definition, the Rata Die number is a date specified as the number of days relative to a base date of December 31 of the year 0. Thus January 1 of the year 1 is Rata Die day 1.


Returns:

double


GetSecond()

Returns the seconds in the given timezone (local one by default).


Returns:

int


GetTicks()

Returns the number of seconds since Jan 1, 1970. An assert failure will occur if the date is not in the range covered by time_t type.


Returns:

time_t


GetWeekDay(weekday)

Returns the copy of this object to which SetToWeekDay was applied.

Parameters:

  • weekday (int)

Returns:

wx.DateTime


GetWeekDayInSameWeek(weekday, flags=wx.DateTime.Monday_First)

Returns the copy of this object to which SetToWeekDayInSameWeek was applied.

Parameters:

  • weekday (int)
  • flag (int)

Returns:

wx.DateTime


GetWeekDayName(weekday, flag=wx.DateTime.Name_Full)

Gets the full (default) or abbreviated (specify wx.DateTime.Name_Abbr name of the given week day.

Parameters:

  • weekday (int)
  • flag (int)

Returns:

string

See also

GetMonthName


GetWeekOfMonth(flags=wx.DateTime.Monday_First, tz=wx.DateTime.Local)

Returns the ordinal number of the week in the month (in 1...5 range).

As GetWeekOfYear, this function supports both conventions for the week start.

Parameters:

  • flags (int)
  • tz (int)

Returns:

int


GetWeekOfYear(flags=wx.DateTime.Monday_First, tz=wx.DateTime.Local)

Returns the number of the week of the year this date is in.

The first week of the year is, according to international standards, the one containing Jan 4 or, equivalently, the first week which has Thursday in this year. Both of these definitions are the same as saying that the first week of the year must contain more than half of its days in this year.

Accordingly, the week number will always be in 1...53 range (52 for non-leap years).

The function depends on the convention specified by the flags argument but its results for wx.DateTime.Sunday_First are not well-defined as the ISO definition quoted above applies to the weeks starting on Monday only.

Parameters:

  • flags (int)
  • tz (int)

Returns:

int


GetYear()

Returns the year in the given timezone (local one by default).


Returns:

int


GetYearDay(yday)

Returns the copy of this object to which SetToYearDay was applied.

Parameters:

  • yday (int)

Returns:

wx.DateTime


IsBetween(t1, t2)

Returns True if IsStrictlyBetween is True or if the date is equal to one of the limit values.

Parameters:


Returns:

bool


IsDST(country=wx.DateTime.Country_Default)

Returns True if the DST is applied for this date in the given country.

Parameters:

  • country (int)

Returns:

int


IsDSTApplicable(year=wx.DateTime.Inv_Year, country=wx.DateTime.Country_Default)

Returns True if DST was used n the given year (the current one by default) in the given country.

Parameters:

  • year (int)
  • country (int)

Returns:

bool


IsEarlierThan(datetime)

Returns True if this date precedes the given one.

Parameters:


Returns:

bool


IsEqualTo(datetime)

Returns True if the two dates are strictly identical.

Parameters:


Returns:

bool


IsEqualUpTo(dt, ts)

Returns True if the date is equal to another one up to the given time interval, i.e. if the absolute difference between the two dates is less than this interval.

Parameters:


Returns:

bool


IsLaterThan(datetime)

Returns True if this date is later than the given one.

Parameters:


Returns:

bool


IsLeapYear(year=wx.DateTime.Inv_Year, cal=wx.DateTime.Gregorian)

Returns True if the year is a leap one in the specified calendar.

This functions supports Gregorian and Julian calendars.

Parameters:

  • year (int)
  • cal (int)

Returns:

bool


IsSameDate(dt)

Returns True if the date is the same without comparing the time parts.

Parameters:


Returns:

bool


IsSameTime(dt)

Returns True if the time is the same (although dates may differ).

Parameters:


Returns:

bool


IsStrictlyBetween(t1, t2)

Returns True if this date lies strictly between the two others,

Parameters:


Returns:

bool

See also

IsBetween


IsValid()

Returns True if the object represents a valid time moment.


Returns:

bool


IsWestEuropeanCountry(country=wx.DateTime.Country_Default)

This function returns True if the specified (or default) country is one of Western European ones.

It is used internally by wx.DateTime to determine the DST convention and date and time formatting rules.

Parameters:

  • country (int)

Returns:

bool


IsWorkDay(country=wx.DateTime.Country_Default)

Returns True is this day is not a holiday in the given country.

Parameters:

  • country (int)

Returns:

bool


MakeFromTimezone()

Same as FromTimezone but modifies the object in place.


Returns:

wx.DateTime


MakeFromUTC(noDST=False)

Parameters:

  • noDST (bool)

Returns:

wx.DateTime


MakeGMT(noDST=False)

Parameters:

  • noDST (bool)

Returns:

wx.DateTime


MakeTimezone(noDST=False)

Modifies the object in place to represent the date in another time zone. If noDST is True, no DST adjustments will be made.


Returns:

wx.DateTime


MakeUTC(noDST=False)

This is the same as calling MakeTimezone with the argument wx.DateTime.GMT0.

Parameters:

  • noDST (bool)

Returns:

wx.DateTime


Now()

Returns the object corresponding to the current time.


Returns:

wx.DateTime

Note

Note that this function is accurate up to second: UNow should be used for better precision (but it is less efficient and might not be available on all platforms).

See also

Today


ParseDate(date)

This function is like ParseDateTime, but it only allows the date to be specified. It is thus less flexible then ParseDateTime, but also has less chances to misinterpret the user input.

Returns None if the conversion failed, otherwise return the pointer to the character which stopped the scan.

Parameters:

  • date (string)

Returns:

string


ParseDateTime(datetime)

Parses the string datetime containing the date and time in free format. This function tries as hard as it can to interpret the given string as date and time. Unlike ParseRfc822Date, it will accept anything that may be accepted and will only reject strings which can not be parsed in any way at all.

Returns None if the conversion failed, otherwise return the pointer to the character which stopped the scan.

Parameters:

  • datetime (string)

Returns:

string


ParseFormat(date, format=wx.DefaultDateTimeFormat, dateDef=wx.DefaultDateTime)

This function parses the string date according to the given format. The system strptime(3) function is used whenever available, but even if it is not, this function is still implemented, although support for locale-dependent format specifiers such as "%c", "%x" or "%X" may not be perfect and GNU extensions such as "%z" and "%Z" are not implemented. This function does handle the month and weekday names in the current locale on all platforms, however.

Please see the description of the ANSI C function strftime(3) for the syntax of the format string.

The dateDef parameter is used to fill in the fields which could not be determined from the format string. For example, if the format is "%d" (the ay of the month), the month and the year are taken from dateDef. If it is not specified, Today is used as the default date.

Returns None if the conversion failed, otherwise return the pointer to the character which stopped the scan.

Parameters:


Returns:

string


ParseRfc822Date(date)

Parses the string date looking for a date formatted according to the RFC 822 in it. The exact description of this format may, of course, be found in the RFC (section 5), but, briefly, this is the format used in the headers of Internet email messages and one of the most common strings expressing date in this format may be something like "Sat, 18 Dec 1999 00:48:30 +0100".

Returns None if the conversion failed, otherwise return the pointer to the character immediately following the part of the string which could be parsed. If the entire string contains only the date in RFC 822 format, the returned pointer will be pointing to a NULL character.

This function is intentionally strict, it will return an error for any string which is not RFC 822 compliant. If you need to parse date formatted in more free ways, you should use ParseDateTime or ParseDate instead.

Parameters:

  • date (string)

Returns:

string


ParseTime(time)

This functions is like ParseDateTime, but only allows the time to be specified in the input string.

Returns None if the conversion failed, otherwise return the pointer to the character which stopped the scan.

Parameters:

  • time (string)

Returns:

string


ResetTime()

Reset time to midnight (00:00:00) without changing the date.


Returns:

wx.DateTime


Set(day, month=wx.DateTime.Inv_Month, year=wx.DateTime.Inv_Year, hour=0, minute=0, second=0, millisec=0)

Sets the date and time from the parameters.

Parameters:

  • day (int)
  • month (int)
  • year (int)
  • hour (int)
  • minute (int)
  • second (int)
  • millisecond (int)

Returns:

wx.DateTime


SetCountry(country)

Sets the country to use by default. This setting influences the DST calculations, date formatting and other things.

Parameters:

  • country (int)

See also

GetCountry


SetDay(day)

Sets the day without changing other date components.

Parameters:

  • day (int)

Returns:

wx.DateTime


SetHMS(hour, minute=0, second=0, millisec=0)

Parameters:

  • hour (int)
  • minute (int)
  • second (int)
  • millisec (int)

Returns:

wx.DateTime


SetHour(hour)

Sets the hour without changing other date components.

Parameters:

  • hour (int)

Returns:

wx.DateTime


SetJDN(jdn)

Parameters:

  • jdn (double)

Returns:

wx.DateTime


SetMillisecond(millisecond)

Sets the millisecond without changing other date components.

Parameters:

  • millisecond (int)

Returns:

wx.DateTime


SetMinute(minute)

Sets the minute without changing other date components.

Parameters:

  • minute (int)

Returns:

wx.DateTime


SetMonth(month)

Sets the month without changing other date components.

Parameters:

  • month (int)

Returns:

wx.DateTime


SetSecond(second)

Sets the second without changing other date components.

Parameters:

  • second (int)

Returns:

wx.DateTime


SetTimeT(timet)

Parameters:

  • timet (time_t)

Returns:

wx.DateTime


SetToCurrent()

Sets the date and time of to the current values. Same as assigning the result of Now to this object.


Returns:

wx.DateTime


SetToLastMonthDay(month=wx.DateTime.Inv_Month, year=wx.DateTime.Inv_Year)

Sets the date to the last day in the specified month (the current one by default). Returns the reference to the modified object itself.

Parameters:

  • month (int)
  • year (int)

Returns:

wx.DateTime


SetToLastWeekDay(weekday, month=wx.DateTime.Inv_Month, year=wx.DateTime.Inv_Year)

The effect of calling this function is the same as of calling SetToWeekDay (-1, weekday, month, year).

The date will be set to the last weekday in the given month and year (the current ones by default).

Always returns True.

Parameters:

  • weekday (int)
  • month (int)
  • year (int)

Returns:

bool


SetToNextWeekDay(weekday)

Sets the date so that it will be the first weekday following the current date.

Returns the reference to the modified object itself.

Parameters:

  • weekday (int)

Returns:

wx.DateTime


SetToPrevWeekDay(weekday)

Sets the date so that it will be the last weekday before the current date.

Returns the reference to the modified object itself.

Parameters:

  • weekday (int)

Returns:

wx.DateTime


SetToWeekDay(weekday, n=1, month=wx.DateTime.Inv_Month, year=wx.DateTime.Inv_Year)

Sets the date to the n -th weekday in the given month of the given year (the current month and year are used by default). The parameter n may be either positive (counting from the beginning of the month) or negative (counting from the end of it).

For example, SetToWeekDay(2, wx.DateTime.Wed) will set the date to the second Wednesday in the current month and SetToWeekDay(-1, wx.DateTime.Sun) – to the last Sunday in it.

Returns True if the date was modified successfully, False otherwise meaning that the specified date doesn’t exist.

Parameters:

  • weekday (int)
  • n (int)
  • month (int)
  • year (int)

Returns:

bool


SetToWeekDayInSameWeek(weekday, flags=wx.DateTime.Monday_First)

Adjusts the date so that it will still lie in the same week as before, but its week day will be the given one.

Returns the reference to the modified object itself.

Parameters:

  • weekday (int)
  • flags (int)

Returns:

wx.DateTime


SetToWeekOfYear(year, numWeek, weekday=wx.DateTime.Mon)

Set the date to the given weekday in the week number numWeek of the given year. The number should be in range 1...53.

Parameters:

  • year (int)
  • numWeek (int)
  • weekday (int)

Returns:

wx.DateTime

Note

Note that the returned date may be in a different year than the one passed to this function because both the week 1 and week 52 or 53 (for leap years) contain days from different years. See GetWeekOfYear for the explanation of how the year weeks are counted.


SetToYearDay(yday)

Sets the date to the day number yday in the same year (i.e., unlike the other functions, this one does not use the current year). The day number should be in the range 1...366 for the leap years and 1...365 for the other ones.

Returns the reference to the modified object itself.

Parameters:

  • yday (int)

Returns:

wx.DateTime


SetYear(year)

Sets the year without changing other date components.

Parameters:

  • year (int)

Returns:

wx.DateTime


Subtract(dt)

Subtracts another date from this one and returns the difference between them as wx.TimeSpan.

Parameters:


Returns:

wx.TimeSpan


SubtractDS(diff)

Subtracts the wx.DateSpan diff from self.

Parameters:


Returns:

wx.DateTime


SubtractTS(diff)

Subtracts the wx.TimeSpan diff from self.

Parameters:


Returns:

wx.DateTime


ToGMT(noDST=False)

Parameters:

  • noDST (bool)

Returns:

wx.DateTime


ToTimezone(noDST=False)

Transform the date to the given time zone. If noDST is True, no DST adjustments will be made.

Returns the date in the new time zone.


Returns:

wx.DateTime


ToUTC(noDST=False)

This is the same as calling ToTimezone with the argument wx.DateTime.GMT0.

Parameters:

  • noDST (bool)

Returns:

wx.DateTime


Today()

Returns the object corresponding to the midnight of the current day (i.e. the same as Now, but the time part is set to 0).


Returns:

wx.DateTime

See also

Now


UNow()

Returns the object corresponding to the current time including the milliseconds if a function to get time with such precision is available on the current platform (supported under most Unices and Win32).


Returns:

wx.DateTime

See also

Now


Properties

Day
See GetDay and SetDay
DayOfYear
See GetDayOfYear
Hour
See GetHour and SetHour
JDN
See GetJDN and SetJDN
JulianDayNumber
See GetJulianDayNumber
LastMonthDay
See GetLastMonthDay
LastWeekDay
See GetLastWeekDay
MJD
See GetMJD
Millisecond
See GetMillisecond and SetMillisecond
Minute
See GetMinute and SetMinute
ModifiedJulianDayNumber
See GetModifiedJulianDayNumber
Month
See GetMonth and SetMonth
NextWeekDay
See GetNextWeekDay
PrevWeekDay
See GetPrevWeekDay
RataDie
See GetRataDie
Second
See GetSecond and SetSecond
Ticks
See GetTicks
Week
See GetWeek
WeekDay
See GetWeekDay
WeekDayInSameWeek
See GetWeekDayInSameWeek
WeekOfMonth
See GetWeekOfMonth
WeekOfYear
See GetWeekOfYear
Year
See GetYear and SetYear
YearDay
See GetYearDay