wx.DateTime¶
wx.DateTime class represents an absolute moment in time.
The type DateTime_t is typedefed as unsigned short and is used to contain the number of years, hours, minutes, seconds and milliseconds.
Global constant wx.DefaultDateTime and synonym for it wx.InvalidDateTime are defined. This constant will be different from any valid wx.DateTime object.
Static Functions¶
All static functions either set or return the static variables of wx.DateSpan (the country), return the current moment, year, month or number of days in it, or do some general calendar-related actions. Please note that although several function accept an extra Calendar parameter, it is currently ignored as only the Gregorian calendar is supported. Future versions will support other calendars.
Date Formatting and Parsing¶
The date formatting and parsing functions convert wx.DateTime objects to and from text. The conversions to text are mostly trivial: you can either do it using the default date and time representations for the current locale ( FormatDate and FormatTime), using the international standard representation defined by ISO 8601 ( FormatISODate, FormatISOTime and FormatISOCombined) or by specifying any format at all and using Format directly. The conversions from text are more interesting, as there are much more possibilities to care about. The simplest cases can be taken care of with ParseFormat which can parse any date in the given (rigid) format. ParseRfc822Date is another function for parsing dates in predefined format – the one of RFC 822 which (still…) defines the format of email messages on the Internet. This format cannot be described with strptime(3)-like format strings used by Format, hence the need for a separate function. But the most interesting functions are ParseTime, ParseDate and ParseDateTime. They try to parse the date and time (or only one of them) in ‘free’ format, i.e. allow them to be specified in any of possible ways. These functions will usually be used to parse the (interactive) user input which is not bound to be in any predefined format. As an example, ParseDate can parse the strings such as “tomorrow”, “March first” and even “next Sunday”. Finally notice that each of the parsing functions is available in several overloads: if the input string is a narrow ( char ) string, then a narrow pointer is returned. If the input string is a wide string, a wide int pointer is returned. Finally, if the input parameter is a String , a narrow int pointer is also returned for backwards compatibility but there is also an additional argument of String.const_iterator type in which, if it is not None, an iterator pointing to the end of the scanned string part is returned.
See also
Date and Time, wx.TimeSpan, wx.DateSpan, wx.adv.CalendarCtrl
Class Hierarchy¶
Methods Summary¶
Default constructor. |
|
Adds the given date span to this object. |
|
Converts the year in absolute notation (i.e. a number which can be negative, positive or zero) to the year in BC/AD notation. |
|
Returns the difference between this object and dt as a wx.DateSpan. |
|
This function does the same as the standard |
|
Identical to calling |
|
Returns the combined date-time representation in the |
|
This function returns the date representation in the |
|
This function returns the time representation in the |
|
Identical to calling |
|
Construct a |
|
Construct a |
|
Construct a |
|
Construct a |
|
Transform the date from the given time zone to the local one. |
|
Returns the translations of the strings |
|
Returns the date and time in |
|
Get the beginning of |
|
Returns the century of this date. |
|
Returns the current default country. |
|
Get the current month in given calendar (only Gregorian is currently supported). |
|
Get the current year in given calendar (only Gregorian is currently supported). |
|
Returns the object having the same date component as this one but time of 00:00:00. |
|
Returns the day in the given timezone (local one by default). |
|
Returns the day of the year (in |
|
Returns the end of |
|
Return the standard English name of the given month. |
|
Return the standard English name of the given week day. |
|
Acquires the first weekday of a week based on locale and/or OS settings. |
|
Returns the hour in the given timezone (local one by default). |
|
Synonym for |
|
Returns the |
|
Returns the copy of this object to which |
|
Returns the copy of this object to which |
|
Synonym for |
|
Returns the milliseconds in the given timezone (local one by default). |
|
Returns the minute in the given timezone (local one by default). |
|
Returns the “Modified Julian Day Number” ( |
|
Returns the month in the given timezone (local one by default). |
|
Gets the full (default) or abbreviated name of the given month. |
|
Returns the copy of this object to which |
|
Returns the number of days in the given month of the given year. |
|
Returns the copy of this object to which |
|
Return the Rata Die number of this date. |
|
Returns the seconds in the given timezone (local one by default). |
|
Returns the number of seconds since Jan 1, 1970 |
|
Returns the current time. |
|
Returns broken down representation of the date and time. |
|
Returns the number of milliseconds since Jan 1, 1970 |
|
Returns the year to which the week containing this date belongs. |
|
Returns the week day in the given timezone (local one by default). |
|
Returns the copy of this object to which |
|
Gets the full (default) or abbreviated name of the given week day. |
|
Returns the ordinal number of the week in the month (in |
|
Returns the number of the week of the year this date is in. |
|
Returns the year in the given timezone (local one by default). |
|
Returns the copy of this object to which |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
This function returns |
|
Returns |
|
Same as |
|
Modifies the object in place to represent the date in another time zone. |
|
This is the same as calling |
|
Returns the object corresponding to the current time in local time zone. |
|
This function is like |
|
Parses the string |
|
Parses the string date according to the given format. |
|
This function parses the string containing the date and time in |
|
This function parses the date in |
|
This function parses the time in |
|
Parses the string date looking for a date formatted according to the |
|
This functions is like |
|
Reset time to midnight (00:00:00) without changing the date. |
|
Sets the date and time from the parameters. |
|
Sets the date to be equal to |
|
Sets the date from the so-called Julian Day Number. |
|
Constructs the object from timet value holding the number of seconds since Jan 1, 1970 |
|
Sets the date and time from the broken down representation in the ` |
|
Sets the country to use by default. |
|
Sets the day without changing other date components. |
|
Sets the date from the date and time in |
|
Sets the hour without changing other date components. |
|
Sets the millisecond without changing other date components. |
|
Sets the minute without changing other date components. |
|
Sets the month without changing other date components. |
|
Sets the second without changing other date components. |
|
Sets the date and time of to the current values. |
|
Sets the date to the last day in the specified month (the current one by default). |
|
The effect of calling this function is the same as of calling |
|
Sets the date so that it will be the first weekday following the current date. |
|
Sets the date so that it will be the last weekday before the current date. |
|
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). |
|
Adjusts the date so that it will still lie in the same week as before, but its week day will be the given one. |
|
Set the date to the given weekday in the week number numWeek of the given year . |
|
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). |
|
Sets the year without changing other date components. |
|
Subtracts the given time span from this object. |
|
Transform the date to the given time zone. |
|
This is the same as calling |
|
Returns the object corresponding to the midnight of the current day (i.e. the same as |
|
Returns the object corresponding to the current time including the milliseconds. |
|
Properties Summary¶
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
Class API¶
- class wx.DateTime(object)¶
Possible constructors:
DateTime() -> None DateTime(date) -> None DateTime(day, month, year=Inv_Year, hour=0, minute=0, second=0, millisec=0) -> None
DateTime class represents an absolute moment in time.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
Use one of the
Setfunctions to initialize the object later.- Return type:
None
__init__ (self, date)
Copy constructor.
- Parameters:
date (wx.DateTime)
- Return type:
None
__init__ (self, day, month, year=Inv_Year, hour=0, minute=0, second=0, millisec=0)
Same as
Set.- Parameters:
day (int)
month (DateTime.Month)
year (int)
hour (int)
minute (int)
second (int)
millisec (int)
- Return type:
None
- Add(self, *args, **kw)¶
-
Add (self, diff)
Adds the given date span to this object.
- Parameters:
diff (wx.DateSpan)
- Return type:
Add (self, diff)
Adds the given time span to this object.
- Parameters:
diff (wx.TimeSpan)
- Return type:
- static 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
BCand so for other years there is a difference of 1.This function should be used like this:
dt = wx.DateTimeFromDMY(8, 5, 1977) y = dt.GetYear() epoch = (y > 0 and ["AD"] or ["BC"])[0] print "The year is %d%s"%(wx.DateTime.ConvertYearToBC(y), epoch)
- Parameters:
year (int)
- Return type:
int
- DiffAsDateSpan(self, dt)¶
Returns the difference between this object and dt as a wx.DateSpan.
This method allows finding the number of entire years, months, weeks and days between dt and this date.
- Parameters:
dt (wx.DateTime)
- Return type:
Added in version 2.9.5.
- Format(self, format=DefaultDateTimeFormat, tz=Local)¶
This function does the same as the standard
ANSICstrftime(3)function (https://cplusplus.com/reference/ctime/strftime/).Please see its description for the meaning of format parameter.
Notice that
POSIX"%g","%G","%V"and"%z"format specifiers are supported even if the standard library doesn’t support them (e.g.MSVC).It also accepts a few Widgets-specific extensions: you can optionally specify the width of the field to follow using
printf(3)-likesyntax and the format specification"%l"can be used to get the number of milliseconds.- Parameters:
format (string)
tz (wx.DateTime.TimeZone)
- Return type:
str
See also
- FormatDate(self)¶
Identical to calling
Formatwith"%x"argument (which means “preferred date representation for the current locale”).- Return type:
str
- FormatISOCombined(self, sep='T')¶
Returns the combined date-time representation in the
ISO8601 format"YYYY-MM-DDTHH:MM:SS".The sep parameter default value produces the result exactly corresponding to the
ISOstandard, but it can also be useful to use a space as separator if a more human-readable combined date-time representation is needed.- Parameters:
sep (int)
- Return type:
str
See also
- FormatISODate(self)¶
This function returns the date representation in the
ISO8601 format"YYYY-MM-DD".- Return type:
str
- FormatISOTime(self)¶
This function returns the time representation in the
ISO8601 format"HH:MM:SS".- Return type:
str
- FormatTime(self)¶
Identical to calling
Formatwith"%X"argument (which means “preferred time representation for the current locale”).- Return type:
str
- static FromDMY(day, month, year=Inv_Year, hour=0, minute=0, second=0, millisecond=0)¶
Construct a
DateTimeusing the supplied parameters.- Return type:
- static FromHMS(hour, minute=0, second=0, millisecond=0)¶
Construct a
DateTimeequal toToday() with the time set to the supplied parameters.- Return type:
- static FromJDN(jdn)¶
Construct a
DateTimefrom a Julian Day Number.By definition, the Julian Day Number, usually abbreviated as
JDN, of a particular instant is the fractional number of days since 12 hours Universal Coordinated Time (Greenwich mean noon) on January 1 of the year -4712 in the Julian proleptic calendar.- Return type:
- static FromTimeT(timet)¶
Construct a
DateTimefrom a Ctime_tvalue, the number of seconds since the epoch.- Return type:
- FromTimezone(self, tz, noDST=False)¶
Transform the date from the given time zone to the local one.
If noDST is
True, noDSTadjustments will be made.If tz parameter is
wx.DateTime.Local, no adjustment is performed.- Parameters:
tz (wx.DateTime.TimeZone)
noDST (bool)
- Return type:
- Returns:
The date adjusted by the different between the given and the local time zones.
- static GetAmPmStrings()¶
Returns the translations of the strings
AMandPMused for time formatting for the current locale.Either of the pointers may be
Noneif the corresponding value is not needed.- Return type:
Tuple[str, str]
- GetAsDOS(self)¶
Returns the date and time in
DOSformat.- Return type:
int
- static GetBeginDST(year=Inv_Year, country=Country_Default)¶
Get the beginning of
DSTfor the given country in the given year (current one by default).This function suffers from limitations described in the DST overview.
- Parameters:
year (int)
country (Country)
- Return type:
See also
- GetCentury(self, tz=Local)¶
Returns the century of this date.
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- static GetCountry()¶
Returns the current default country.
The default country is used for
DSTcalculations, for example.- Return type:
See also
- static GetCurrentMonth(cal=Gregorian)¶
Get the current month in given calendar (only Gregorian is currently supported).
- Parameters:
cal (Calendar)
- Return type:
- static GetCurrentYear(cal=Gregorian)¶
Get the current year in given calendar (only Gregorian is currently supported).
- Parameters:
cal (Calendar)
- Return type:
int
- GetDateOnly(self)¶
Returns the object having the same date component as this one but time of 00:00:00.
- Return type:
Added in version 2.8.2.
See also
- GetDay(self, tz=Local)¶
Returns the day in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetDayOfYear(self, tz=Local)¶
Returns the day of the year (in
1-366range) in the given timezone (local one by default).- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- static GetEndDST(year=Inv_Year, country=Country_Default)¶
Returns the end of
DSTfor the given country in the given year (current one by default).- Parameters:
year (int)
country (Country)
- Return type:
See also
- static GetEnglishMonthName(month, flags=Name_Full)¶
Return the standard English name of the given month.
This function always returns “January” or “Jan” for January, use
GetMonthNameto retrieve the name of the month in the users current locale.- Parameters:
month (DateTime.Month) – One of
wx.DateTime.Jan, …,wx.DateTime.Decvalues.flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
- Return type:
str
Added in version 2.9.0.
See also
- static GetEnglishWeekDayName(weekday, flags=Name_Full)¶
Return the standard English name of the given week day.
This function always returns “Monday” or “Mon” for Monday, use
GetWeekDayNameto retrieve the name of the month in the users current locale.- Parameters:
weekday (DateTime.WeekDay) – One of
wx.DateTime.Sun, …,wx.DateTime.Satvalues.flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
- Return type:
str
Added in version 2.9.0.
See also
- static GetFirstWeekDay(firstDay)¶
Acquires the first weekday of a week based on locale and/or OS settings.
If the information was not available, returns
Sun.- Parameters:
firstDay (WeekDay) – The address of a WeekDay variable to which the first weekday will be assigned to.
- Return type:
bool
- Returns:
If the first day could not be determined, returns
False, and firstDay is set to a fallback value.
Added in version 4.1/wxWidgets-3.1.1.
- GetHour(self, tz=Local)¶
Returns the hour in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetJDN(self)¶
Synonym for
GetJulianDayNumber.- Return type:
float
- GetJulianDayNumber(self)¶
Returns the
JDNcorresponding to this date.Beware of rounding errors!
- Return type:
float
See also
- GetLastMonthDay(self, month=Inv_Month, year=Inv_Year)¶
Returns the copy of this object to which
SetToLastMonthDaywas applied.- Parameters:
month (DateTime.Month)
year (int)
- Return type:
- GetLastWeekDay(self, weekday, month=Inv_Month, year=Inv_Year)¶
Returns the copy of this object to which
SetToLastWeekDaywas applied.- Parameters:
weekday (DateTime.WeekDay)
month (DateTime.Month)
year (int)
- Return type:
- GetMJD(self)¶
Synonym for
GetModifiedJulianDayNumber.- Return type:
float
- GetMillisecond(self, tz=Local)¶
Returns the milliseconds in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetMinute(self, tz=Local)¶
Returns the minute in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetModifiedJulianDayNumber(self)¶
Returns the “Modified Julian Day Number” (
MJD) which is, by definition, is equal toJDN- 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 the noons like
JDN. TheMJD0 represents Nov 17, 1858.- Return type:
float
- GetMonth(self, tz=Local)¶
Returns the month in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
- static GetMonthName(month, flags=Name_Full)¶
Gets the full (default) or abbreviated name of the given month.
This function returns the name in the current locale, use
GetEnglishMonthNameto get the untranslated name if necessary.- Parameters:
month (DateTime.Month) – One of
wx.DateTime.Jan, …,wx.DateTime.Decvalues.flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
- Return type:
str
See also
- GetNextWeekDay(self, weekday)¶
Returns the copy of this object to which
SetToNextWeekDaywas applied.- Parameters:
weekday (DateTime.WeekDay)
- Return type:
- static GetNumberOfDays(month, year=Inv_Year, cal=Gregorian)¶
Returns the number of days in the given month of the given year.
The only supported value for cal currently is
Gregorian.- Parameters:
month (DateTime.Month)
year (int)
cal (Calendar)
- Return type:
int
- GetPrevWeekDay(self, weekday)¶
Returns the copy of this object to which
SetToPrevWeekDaywas applied.- Parameters:
weekday (DateTime.WeekDay)
- Return type:
- GetRataDie(self)¶
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.
- Return type:
float
- GetSecond(self, tz=Local)¶
Returns the seconds in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetTicks(self)¶
Returns the number of seconds since Jan 1, 1970
UTC.This function is provided solely for interoperability with the standard C library and other libraries using
time_tvalues. If you just need to get the value represented by this object as a number, useGetValueinstead, which doesn’t lose precision and covers the entire supported range of dates, unlike this one which is limited to the range of positive 32 bit values, i.e. from Jan 1, 1970 to around Jan 19, 2038 and returns-1for the dates outside of it.Additionally, this method must be called on an initialized date object and an assertion failure occurs if it is called on an object for which
IsValidisFalse.- Return type:
int
- static GetTimeNow()¶
Returns the current time.
- Return type:
int
- GetTm(self, tz=Local)¶
Returns broken down representation of the date and time.
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
- GetValue(self)¶
Returns the number of milliseconds since Jan 1, 1970
UTC.Directly returns the internal representation of wx.DateTime object as the number of milliseconds (positive or negative) since the Unix/C epoch.
- Return type:
int
- GetWeekBasedYear(self, tz)¶
Returns the year to which the week containing this date belongs.
The value returned by this function is the same as the year, except, possibly, for a few days at the very beginning and very end of the year if they belong to a week which is mostly (i.e. at least 4 days) is in another year in which case that other (previous or next) year is returned.
For example, January 1 in 2015 belongs to the first year of 2015, hence
GetWeekOfYearfor it returns 1 and this function returns 2015. However January 1 in 2016 belongs to the last week of 2015 according toISO8601 standard rules and soGetWeekOfYearreturns 53 and this function returns 2015, althoughGetYearreturns 2016.- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
Added in version 4.1/wxWidgets-3.1.0.
- GetWeekDay(self, *args, **kw)¶
-
GetWeekDay (self, tz=Local)
Returns the week day in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
GetWeekDay (self, weekday, n=1, month=Inv_Month, year=Inv_Year)
Returns the copy of this object to which
SetToWeekDaywas applied.- Parameters:
weekday (DateTime.WeekDay)
n (int)
month (DateTime.Month)
year (int)
- Return type:
- GetWeekDayInSameWeek(self, weekday, flags=Monday_First)¶
Returns the copy of this object to which
SetToWeekDayInSameWeekwas applied.- Parameters:
weekday (DateTime.WeekDay)
flags (WeekFlags)
- Return type:
- static GetWeekDayName(weekday, flags=Name_Full)¶
Gets the full (default) or abbreviated name of the given week day.
This function returns the name in the current locale, use
GetEnglishWeekDayNameto get the untranslated name if necessary.- Parameters:
weekday (DateTime.WeekDay) – One of
wx.DateTime.Sun, …,wx.DateTime.Satvalues.flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
- Return type:
str
See also
- GetWeekOfMonth(self, flags=Monday_First, tz=Local)¶
Returns the ordinal number of the week in the month (in
1-5range).As
GetWeekOfYear, this function supports both conventions for the week start.- Parameters:
flags (WeekFlags)
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetWeekOfYear(self, flags=Monday_First, tz=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-53range (52 for non-leap years).The function depends on the week start convention specified by the flags argument but its results for
Sunday_Firstare not well-defined as theISOdefinition quoted above applies to the weeks starting on Monday only.- Parameters:
flags (WeekFlags)
tz (wx.DateTime.TimeZone)
- Return type:
int
See also
- GetYear(self, tz=Local)¶
Returns the year in the given timezone (local one by default).
- Parameters:
tz (wx.DateTime.TimeZone)
- Return type:
int
- GetYearDay(self, yday)¶
Returns the copy of this object to which
SetToYearDaywas applied.- Parameters:
yday (int)
- Return type:
- IsBetween(self, t1, t2)¶
Returns
TrueifIsStrictlyBetweenisTrueor if the date is equal to one of the limit values.- Parameters:
t1 (wx.DateTime)
t2 (wx.DateTime)
- Return type:
bool
See also
- IsDST(self, country=Country_Default)¶
Returns
Trueif theDSTis applied for this date in the given country.- Parameters:
country (Country)
- Return type:
int
See also
- static IsDSTApplicable(year=Inv_Year, country=Country_Default)¶
Returns
TrueifDSTwas used in the given year (the current one by default) in the given country.- Parameters:
year (int)
country (Country)
- Return type:
bool
- IsEarlierThan(self, datetime)¶
Returns
Trueif this date precedes the given one.- Parameters:
datetime (wx.DateTime)
- Return type:
bool
- IsEqualTo(self, datetime)¶
Returns
Trueif the two dates are strictly identical.- Parameters:
datetime (wx.DateTime)
- Return type:
bool
- IsEqualUpTo(self, dt, ts)¶
Returns
Trueif 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:
dt (wx.DateTime)
ts (wx.TimeSpan)
- Return type:
bool
- IsLaterThan(self, datetime)¶
Returns
Trueif this date is later than the given one.- Parameters:
datetime (wx.DateTime)
- Return type:
bool
- static IsLeapYear(year=Inv_Year, cal=Gregorian)¶
Returns
Trueif theyearis a leap one in the specified calendar.This functions supports Gregorian and Julian calendars.
- Parameters:
year (int)
cal (Calendar)
- Return type:
bool
- IsSameDate(self, dt)¶
Returns
Trueif the date is the same without comparing the time parts.- Parameters:
dt (wx.DateTime)
- Return type:
bool
- IsSameTime(self, dt)¶
Returns
Trueif the time is the same (although dates may differ).- Parameters:
dt (wx.DateTime)
- Return type:
bool
- IsStrictlyBetween(self, t1, t2)¶
Returns
Trueif this date lies strictly between the two given dates.- Parameters:
t1 (wx.DateTime)
t2 (wx.DateTime)
- Return type:
bool
See also
- IsValid(self)¶
Returns
Trueif the object represents a valid time moment.- Return type:
bool
- static IsWestEuropeanCountry(country=Country_Default)¶
This function returns
Trueif the specified (or default) country is one of Western European ones.It is used internally by wx.DateTime to determine the
DSTconvention and date and time formatting rules.- Parameters:
country (Country)
- Return type:
bool
- IsWorkDay(self, country=Country_Default)¶
Returns
Trueis this day is not a holiday in the given country.- Parameters:
country (Country)
- Return type:
bool
- MakeFromTimezone(self, tz, noDST=False)¶
Same as
FromTimezonebut modifies the object in place.- Parameters:
tz (wx.DateTime.TimeZone)
noDST (bool)
- Return type:
- MakeTimezone(self, tz, noDST=False)¶
Modifies the object in place to represent the date in another time zone.
If noDST is
True, noDSTadjustments will be made.- Parameters:
tz (wx.DateTime.TimeZone)
noDST (bool)
- Return type:
- MakeUTC(self, noDST=False)¶
This is the same as calling
MakeTimezonewith the argumentGMT0.- Parameters:
noDST (bool)
- Return type:
- static Now()¶
Returns the object corresponding to the current time in local time zone.
Example:
now = wx.DateTime.Now() print "Current time in Paris:\t%s\n"%(now.Format("%c", wx.DateTime.CET))
- Return type:
Note
This function is accurate up to seconds.
UNowcan be used if better precision is required.See also
- ParseDate(self, 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.See
ParseFormatfor the description of function parameters and return value.- Parameters:
date (string)
- Return type:
int
See also
- ParseDateTime(self, datetime)¶
Parses the string
datetimecontaining 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 cannot be parsed in any way at all. Notice that the function will fail if either date or time part is present but not both, useParseDateorParseTimeto parse strings containing just the date or time component.See
ParseFormatfor the description of function parameters and return value.- Parameters:
datetime (string)
- Return type:
int
- ParseFormat(self, *args, **kw)¶
-
ParseFormat (self, date, format, dateDef)
Parses the string date according to the given format.
This function is similar to
strptime(3)but doesn’t use it and implements the parsing itself, with support for all the standard (POSIX) formatting specifiers as well as a number ofGNUextensions such asl,F,z(but notZ, currently) etc.Please see the description of the
ANSIC functionstrftime(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 day of the month), the month and the year are taken from dateDef. If it is not specified,Todayis used as the default date.Example of using this function:
dt = wx.DateTime() # Uninitialized datetime bDate = "25/12/2012" if dt.ParseFormat(bDate, "%d-%m-%Y") == -1: # This datetime format is wrong on purpose print "Wrong format" elif dt.ParseFormat(bDate, "%d/%m/%Y") >= 0: # This is correct print "Format OK!", dt
- Parameters:
date (string) – The string to be parsed.
format (string) – strptime()-like format string.
dateDef (wx.DateTime) – Used to fill in the date components not specified in the date string.
- Return type:
int
- Returns:
-1 if the parse failed, the number of characters parsed otherwise.
See also
ParseFormat (self, date, format)
This version of the
ParseFormatmethod works the same, but with missing values filled in fromToday.- Parameters:
date (string)
format (string)
- Return type:
int
ParseFormat (self, date)
This version uses “%c” as the format code, which is the same default used by
Format.- Parameters:
date (string)
- Return type:
int
- ParseISOCombined(self, date, sep='T')¶
This function parses the string containing the date and time in
ISO8601 combined format"YYYY-MM-DDTHH:MM:SS".The separator between the date and time parts must be equal to sep for the function to succeed.
- Parameters:
date (string)
sep (int)
- Return type:
bool
- Returns:
Trueif the entire string was parsed successfully,Falseotherwise.
- ParseISODate(self, date)¶
This function parses the date in
ISO8601 format"YYYY-MM-DD".- Parameters:
date (string)
- Return type:
bool
- Returns:
Trueif the entire string was parsed successfully,Falseotherwise.
- ParseISOTime(self, date)¶
This function parses the time in
ISO8601 format"HH:MM:SS".- Parameters:
date (string)
- Return type:
bool
- Returns:
Trueif the entire string was parsed successfully,Falseotherwise.
- ParseRfc822Date(self, date)¶
Parses the string date looking for a date formatted according to the
RFC822 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
Noneif 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 inRFC822 format, the returned pointer will be pointing to aNULcharacter.This function is intentionally strict, it will return an error for any string which is not
RFC822 compliant. If you need to parse date formatted in more free ways, you should useParseDateTimeorParseDateinstead.See
ParseFormatfor the description of function parameters and return value.- Parameters:
date (string)
- Return type:
int
- ParseTime(self, time)¶
This functions is like
ParseDateTime, but only allows the time to be specified in the input string.See
ParseFormatfor the description of function parameters and return value.- Parameters:
time (string)
- Return type:
int
- ResetTime(self)¶
Reset time to midnight (00:00:00) without changing the date.
- Return type:
- Set(self, day, month, year=Inv_Year, hour=0, minute=0, second=0, millisec=0)¶
Sets the date and time from the parameters.
If the function parameters are invalid, e.g.
monthis February anddayis 30, the object is left in an invalid state, i.e.IsValidmethod will returnFalse.If the specified time moment is invalid due to
DST, i.e. it falls into the “missing” hour on the date on which theDSTstarts, a valid wx.DateTime object is still constructed but its hour component is moved forward to ensure that it corresponds to a valid moment in the local time zone. For example, in theCETtime zone theDSTstarted on 2013-03-31T02:00:00 in 2013 and so setting the object to 2:30 at this date actually sets the hour to 3, and not 2.- Parameters:
day (int)
month (DateTime.Month)
year (int)
hour (int)
minute (int)
second (int)
millisec (int)
- Return type:
- SetHMS(self, hour, minute=0, second=0, millisec=0)¶
Sets the date to be equal to
Todayand the time from supplied parameters.See the full
Setoverload for the remarks aboutDST.- Parameters:
hour (int)
minute (int)
second (int)
millisec (int)
- Return type:
- SetJDN(self, jdn)¶
Sets the date from the so-called Julian Day Number.
By definition, the Julian Day Number, usually abbreviated as
JDN, of a particular instant is the fractional number of days since 12 hours Universal Coordinated Time (Greenwich mean noon) on January 1 of the year -4712 in the Julian proleptic calendar.- Parameters:
jdn (float)
- Return type:
- SetTimeT(self, timet)¶
Constructs the object from timet value holding the number of seconds since Jan 1, 1970
UTC.If timet is invalid, i.e.:
-1
wx.DateTime becomes invalid too, i.e. its
IsValidwill returnFalse.- Parameters:
timet (int)
- Return type:
- SetTm(self, tm)¶
Sets the date and time from the broken down representation in the `
wx.DateTime.Tm` structure.- Parameters:
tm (wx.DateTime.Tm)
- Return type:
- static SetCountry(country)¶
Sets the country to use by default.
This setting influences the
DSTcalculations, date formatting and other things.- Parameters:
country (Country)
- Return type:
None
See also
- SetDay(self, day)¶
Sets the day without changing other date components.
- Parameters:
day (int)
- Return type:
- SetFromDOS(self, ddt)¶
Sets the date from the date and time in
DOSformat.- Parameters:
ddt (long)
- Return type:
- SetHour(self, hour)¶
Sets the hour without changing other date components.
- Parameters:
hour (int)
- Return type:
- SetMillisecond(self, millisecond)¶
Sets the millisecond without changing other date components.
- Parameters:
millisecond (int)
- Return type:
- SetMinute(self, minute)¶
Sets the minute without changing other date components.
- Parameters:
minute (int)
- Return type:
- SetMonth(self, month)¶
Sets the month without changing other date components.
- Parameters:
month (DateTime.Month)
- Return type:
- SetSecond(self, second)¶
Sets the second without changing other date components.
- Parameters:
second (int)
- Return type:
- SetToCurrent(self)¶
Sets the date and time of to the current values.
Same as assigning the result of
wx.Nowto this object.- Return type:
- SetToLastMonthDay(self, month=Inv_Month, year=Inv_Year)¶
Sets the date to the last day in the specified month (the current one by default).
- Parameters:
month (DateTime.Month)
year (int)
- Return type:
- Returns:
The reference to the modified object itself.
- SetToLastWeekDay(self, weekday, month=Inv_Month, year=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 (DateTime.WeekDay)
month (DateTime.Month)
year (int)
- Return type:
bool
- SetToNextWeekDay(self, weekday)¶
Sets the date so that it will be the first weekday following the current date.
- Parameters:
weekday (DateTime.WeekDay)
- Return type:
- Returns:
The reference to the modified object itself.
- SetToPrevWeekDay(self, weekday)¶
Sets the date so that it will be the last weekday before the current date.
- Parameters:
weekday (DateTime.WeekDay)
- Return type:
- Returns:
The reference to the modified object itself.
- SetToWeekDay(self, weekday, n=1, month=Inv_Month, year=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(wxDateTime.Wed, 2) will set the date to the second Wednesday in the current month and SetToWeekDay(
wx.DateTime.Sun, -1) will set the date to the last Sunday in the current month.Note that leaving the month or year parameters as their default values will result in the current month or year being substituted, overwriting any previous values in the wx.DateTime object.
- Parameters:
weekday (DateTime.WeekDay)
n (int)
month (DateTime.Month)
year (int)
- Return type:
bool
- Returns:
Trueif the date was modified successfully,Falseotherwise meaning that the specified date doesn’t exist.
- SetToWeekDayInSameWeek(self, weekday, flags=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.
- Parameters:
weekday (DateTime.WeekDay)
flags (WeekFlags)
- Return type:
- Returns:
The reference to the modified object itself.
- static SetToWeekOfYear(year, numWeek, weekday=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.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
GetWeekOfYearfor the explanation of how the year weeks are counted.- Parameters:
year (int)
numWeek (int)
weekday (DateTime.WeekDay)
- Return type:
- SetToYearDay(self, 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-366for the leap years and1-365for the other ones.- Parameters:
yday (int)
- Return type:
- Returns:
The reference to the modified object itself.
- SetYear(self, year)¶
Sets the year without changing other date components.
- Parameters:
year (int)
- Return type:
- Subtract(self, *args, **kw)¶
-
Subtract (self, diff)
Subtracts the given time span from this object.
- Parameters:
diff (wx.TimeSpan)
- Return type:
Subtract (self, diff)
Subtracts the given date span from this object.
- Parameters:
diff (wx.DateSpan)
- Return type:
Subtract (self, dt)
Subtracts another date from this one and returns the difference between them as a wx.TimeSpan.
- Parameters:
dt (wx.DateTime)
- Return type:
- ToTimezone(self, tz, noDST=False)¶
Transform the date to the given time zone.
If noDST is
True, noDSTadjustments will be made.If tz parameter is
wx.DateTime.Local, no adjustment is performed.- Parameters:
tz (wx.DateTime.TimeZone)
noDST (bool)
- Return type:
- Returns:
The date adjusted by the different between the local and the given time zones.
- ToUTC(self, noDST=False)¶
This is the same as calling
ToTimezonewith the argumentGMT0.- Parameters:
noDST (bool)
- Return type:
- static Today()¶
Returns the object corresponding to the midnight of the current day (i.e. the same as
wx.Now, but the time part is set to 0).- Return type:
See also
- static UNow()¶
Returns the object corresponding to the current time including the milliseconds.
Like
wx.Now, this method creates the wx.DateTime object corresponding to the current moment in local time.- Return type:
See also
wx.Now,GetUTCTimeMillis
- __repr__(self)¶
- __str__(self)¶
Properties¶
- DayOfYear¶
See
GetDayOfYear
- JulianDayNumber¶
- LastMonthDay¶
See
GetLastMonthDay
- ModifiedJulianDayNumber¶
- RataDie¶
See
GetRataDie
- WeekOfMonth¶
See
GetWeekOfMonth
- WeekOfYear¶
See
GetWeekOfYear
- millisecond¶
See
GetMillisecondandSetMillisecond
