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.
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.
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.
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. |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
wx.
DateTime
(object)¶Possible constructors:
DateTime()
DateTime(date)
DateTime(day, month, year=Inv_Year, hour=0, minute=0, second=0,
millisec=0)
DateTime class represents an absolute moment in time.
__init__
(self, *args, **kw)¶__init__ (self)
Default constructor.
Use one of the Set
functions to initialize the object later.
__init__ (self, date)
Copy constructor.
date (wx.DateTime) –
__init__ (self, day, month, year=Inv_Year, hour=0, minute=0, second=0, millisec=0)
Same as Set
.
day (int) –
month (DateTime.Month) –
year (int) –
hour (int) –
minute (int) –
second (int) –
millisec (int) –
Add
(self, *args, **kw)¶Add (self, diff)
Adds the given date span to this object.
diff (wx.DateSpan) –
Add (self, diff)
Adds the given time span to this object.
diff (wx.TimeSpan) –
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.
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)
year (int) –
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.
dt (wx.DateTime) –
New in version 2.9.5.
Format
(self, format=DefaultDateTimeFormat, tz=Local)¶This function does the same as the standard ANSI
C strftime(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)-like
syntax and the format specification "%l"
can be used to get the number of milliseconds.
format (string) –
tz (wx.DateTime.TimeZone) –
string
See also
FormatDate
(self)¶Identical to calling Format
with "%x"
argument (which means “preferred date representation for the current locale”).
string
FormatISOCombined
(self, sep='T')¶Returns the combined date-time representation in the ISO
8601 format "YYYY-MM-DDTHH:MM:SS"
.
The sep parameter default value produces the result exactly corresponding to the ISO
standard, but it can also be useful to use a space as separator if a more human-readable combined date-time representation is needed.
sep (int) –
string
See also
FormatISODate
(self)¶This function returns the date representation in the ISO
8601 format "YYYY-MM-DD"
.
string
FormatISOTime
(self)¶This function returns the time representation in the ISO
8601 format "HH:MM:SS"
.
string
FormatTime
(self)¶Identical to calling Format
with "%X"
argument (which means “preferred time representation for the current locale”).
string
FromDMY
(day, month, year=Inv_Year, hour=0, minute=0, second=0, millisecond=0)¶Construct a DateTime
using the supplied parameters.
FromHMS
(hour, minute=0, second=0, millisecond=0)¶Construct a DateTime
equal to Today
() with the time set to the supplied parameters.
FromJDN
(jdn)¶Construct a DateTime
from 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.
FromTimeT
(timet)¶Construct a DateTime
from a C time_t
value, the number of seconds since the epoch.
FromTimezone
(self, 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.
If tz parameter is wx.DateTime.Local
, no adjustment is performed.
tz (wx.DateTime.TimeZone) –
noDST (bool) –
The date adjusted by the different between the given and the local time zones.
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.
tuple
( am, pm )
GetAsDOS
(self)¶Returns the date and time in DOS
format.
int
GetBeginDST
(year=Inv_Year, country=Country_Default)¶Get the beginning of DST
for the given country in the given year (current one by default).
This function suffers from limitations described in the DST overview.
year (int) –
country (Country) –
See also
GetCentury
(self, tz=Local)¶Returns the century of this date.
tz (wx.DateTime.TimeZone) –
int
GetCountry
()¶Returns the current default country.
The default country is used for DST
calculations, for example.
See also
GetCurrentMonth
(cal=Gregorian)¶Get the current month in given calendar (only Gregorian is currently supported).
cal (Calendar) –
GetCurrentYear
(cal=Gregorian)¶Get the current year in given calendar (only Gregorian is currently supported).
cal (Calendar) –
int
GetDateOnly
(self)¶Returns the object having the same date component as this one but time of 00:00:00.
New in version 2.8.2.
See also
GetDay
(self, tz=Local)¶Returns the day in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
intshort
GetDayOfYear
(self, tz=Local)¶Returns the day of the year (in 1-366
range) in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
intshort
GetEndDST
(year=Inv_Year, country=Country_Default)¶Returns the end of DST
for the given country in the given year (current one by default).
year (int) –
country (Country) –
See also
GetEnglishMonthName
(month, flags=Name_Full)¶Return the standard English name of the given month.
This function always returns “January” or “Jan” for January, use GetMonthName
to retrieve the name of the month in the users current locale.
month (DateTime.Month) – One of wx.DateTime.Jan
, …, wx.DateTime.Dec
values.
flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
string
New in version 2.9.0.
See also
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 GetWeekDayName
to retrieve the name of the month in the users current locale.
weekday (DateTime.WeekDay) – One of wx.DateTime.Sun
, …, wx.DateTime.Sat
values.
flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
string
New in version 2.9.0.
See also
GetFirstWeekDay
(firstDay)¶Acquires the first weekday of a week based on locale and/or OS settings.
If the information was not available, returns Sun
.
firstDay (WeekDay) – The address of a WeekDay variable to which the first weekday will be assigned to.
bool
If the first day could not be determined, returns False
, and firstDay is set to a fallback value.
New in version 4.1/wxWidgets-3.1.1.
GetHour
(self, tz=Local)¶Returns the hour in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
intshort
GetJDN
(self)¶Synonym for GetJulianDayNumber
.
float
GetJulianDayNumber
(self)¶Returns the JDN
corresponding to this date.
Beware of rounding errors!
float
See also
GetLastMonthDay
(self, month=Inv_Month, year=Inv_Year)¶Returns the copy of this object to which SetToLastMonthDay
was applied.
month (DateTime.Month) –
year (int) –
GetLastWeekDay
(self, weekday, month=Inv_Month, year=Inv_Year)¶Returns the copy of this object to which SetToLastWeekDay
was applied.
weekday (DateTime.WeekDay) –
month (DateTime.Month) –
year (int) –
GetMJD
(self)¶Synonym for GetModifiedJulianDayNumber
.
float
GetMillisecond
(self, tz=Local)¶Returns the milliseconds in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
intshort
GetMinute
(self, tz=Local)¶Returns the minute in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
intshort
GetModifiedJulianDayNumber
(self)¶Returns the “Modified Julian Day Number” (MJD
) which is, by definition, is 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 the noons like JDN
. The MJD
0 represents Nov 17, 1858.
float
GetMonth
(self, tz=Local)¶Returns the month in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
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 GetEnglishMonthName
to get the untranslated name if necessary.
month (DateTime.Month) – One of wx.DateTime.Jan
, …, wx.DateTime.Dec
values.
flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
string
See also
GetNextWeekDay
(self, weekday)¶Returns the copy of this object to which SetToNextWeekDay
was applied.
weekday (DateTime.WeekDay) –
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
.
month (DateTime.Month) –
year (int) –
cal (Calendar) –
intshort
GetPrevWeekDay
(self, weekday)¶Returns the copy of this object to which SetToPrevWeekDay
was applied.
weekday (DateTime.WeekDay) –
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.
float
GetSecond
(self, tz=Local)¶Returns the seconds in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
intshort
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_t
values. If you just need to get the value represented by this object as a number, use GetValue
instead, 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 -1
for 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 IsValid
is False
.
int
GetTimeNow
()¶Returns the current time.
int
GetTm
(self, tz=Local)¶Returns broken down representation of the date and time.
tz (wx.DateTime.TimeZone) –
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.
long
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 GetWeekOfYear
for it returns 1 and this function returns 2015. However January 1 in 2016 belongs to the last week of 2015 according to ISO
8601 standard rules and so GetWeekOfYear
returns 53 and this function returns 2015, although GetYear
returns 2016.
tz (wx.DateTime.TimeZone) –
int
New 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).
tz (wx.DateTime.TimeZone) –
GetWeekDay (self, weekday, n=1, month=Inv_Month, year=Inv_Year)
Returns the copy of this object to which SetToWeekDay
was applied.
weekday (DateTime.WeekDay) –
n (int) –
month (DateTime.Month) –
year (int) –
GetWeekDayInSameWeek
(self, weekday, flags=Monday_First)¶Returns the copy of this object to which SetToWeekDayInSameWeek
was applied.
weekday (DateTime.WeekDay) –
flags (WeekFlags) –
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 GetEnglishWeekDayName
to get the untranslated name if necessary.
weekday (DateTime.WeekDay) – One of wx.DateTime.Sun
, …, wx.DateTime.Sat
values.
flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
string
See also
GetWeekOfMonth
(self, flags=Monday_First, tz=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.
flags (WeekFlags) –
tz (wx.DateTime.TimeZone) –
intshort
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-53
range (52 for non-leap years).
The function depends on the week start convention specified by the flags argument but its results for Sunday_First
are not well-defined as the ISO
definition quoted above applies to the weeks starting on Monday only.
flags (WeekFlags) –
tz (wx.DateTime.TimeZone) –
intshort
See also
GetYear
(self, tz=Local)¶Returns the year in the given timezone (local one by default).
tz (wx.DateTime.TimeZone) –
int
GetYearDay
(self, yday)¶Returns the copy of this object to which SetToYearDay
was applied.
yday (int) –
IsBetween
(self, t1, t2)¶Returns True
if IsStrictlyBetween
is True
or if the date is equal to one of the limit values.
t1 (wx.DateTime) –
t2 (wx.DateTime) –
bool
See also
IsDST
(self, country=Country_Default)¶Returns True
if the DST
is applied for this date in the given country.
country (Country) –
int
See also
IsDSTApplicable
(year=Inv_Year, country=Country_Default)¶Returns True
if DST
was used in the given year (the current one by default) in the given country.
year (int) –
country (Country) –
bool
IsEarlierThan
(self, datetime)¶Returns True
if this date precedes the given one.
datetime (wx.DateTime) –
bool
IsEqualTo
(self, datetime)¶Returns True
if the two dates are strictly identical.
datetime (wx.DateTime) –
bool
IsEqualUpTo
(self, 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.
dt (wx.DateTime) –
ts (wx.TimeSpan) –
bool
IsLaterThan
(self, datetime)¶Returns True
if this date is later than the given one.
datetime (wx.DateTime) –
bool
IsLeapYear
(year=Inv_Year, cal=Gregorian)¶Returns True
if the year
is a leap one in the specified calendar.
This functions supports Gregorian and Julian calendars.
year (int) –
cal (Calendar) –
bool
IsSameDate
(self, dt)¶Returns True
if the date is the same without comparing the time parts.
dt (wx.DateTime) –
bool
IsSameTime
(self, dt)¶Returns True
if the time is the same (although dates may differ).
dt (wx.DateTime) –
bool
IsStrictlyBetween
(self, t1, t2)¶Returns True
if this date lies strictly between the two given dates.
t1 (wx.DateTime) –
t2 (wx.DateTime) –
bool
See also
IsValid
(self)¶Returns True
if the object represents a valid time moment.
bool
IsWestEuropeanCountry
(country=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.
country (Country) –
bool
IsWorkDay
(self, country=Country_Default)¶Returns True
is this day is not a holiday in the given country.
country (Country) –
bool
MakeFromTimezone
(self, tz, noDST=False)¶Same as FromTimezone
but modifies the object in place.
tz (wx.DateTime.TimeZone) –
noDST (bool) –
MakeTimezone
(self, tz, 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.
tz (wx.DateTime.TimeZone) –
noDST (bool) –
MakeUTC
(self, noDST=False)¶This is the same as calling MakeTimezone
with the argument GMT0
.
noDST (bool) –
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))
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 ParseFormat
for the description of function parameters and return value.
date (string) –
int
See also
ParseDateTime
(self, 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 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, use ParseDate
or ParseTime
to parse strings containing just the date or time component.
See ParseFormat
for the description of function parameters and return value.
datetime (string) –
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 of GNU
extensions such as l
, F
, z
(but not Z
, currently) etc.
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 day of the month), the month and the year are taken from dateDef. If it is not specified, Today
is 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
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.
int
-1 if the parse failed, the number of characters parsed otherwise.
See also
ParseFormat (self, date, format)
This version of the ParseFormat
method works the same, but with missing values filled in from Today
.
date (string) –
format (string) –
int
ParseFormat (self, date)
This version uses “%c” as the format code, which is the same default used by Format
.
date (string) –
int
ParseISOCombined
(self, date, sep='T')¶This function parses the string containing the date and time in ISO
8601 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.
date (string) –
sep (int) –
bool
True
if the entire string was parsed successfully, False
otherwise.
ParseISODate
(self, date)¶This function parses the date in ISO
8601 format "YYYY-MM-DD"
.
date (string) –
bool
True
if the entire string was parsed successfully, False
otherwise.
ParseISOTime
(self, date)¶This function parses the time in ISO
8601 format "HH:MM:SS"
.
date (string) –
bool
True
if the entire string was parsed successfully, False
otherwise.
ParseRfc822Date
(self, 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 NUL
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.
See ParseFormat
for the description of function parameters and return value.
date (string) –
int
ParseTime
(self, time)¶This functions is like ParseDateTime
, but only allows the time to be specified in the input string.
See ParseFormat
for the description of function parameters and return value.
time (string) –
int
ResetTime
(self)¶Reset time to midnight (00:00:00) without changing the date.
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. month
is February and day
is 30, the object is left in an invalid state, i.e. IsValid
method will return False
.
If the specified time moment is invalid due to DST
, i.e. it falls into the “missing” hour on the date on which the DST
starts, 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 the CET
time zone the DST
started 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.
day (int) –
month (DateTime.Month) –
year (int) –
hour (int) –
minute (int) –
second (int) –
millisec (int) –
SetHMS
(self, hour, minute=0, second=0, millisec=0)¶Sets the date to be equal to Today
and the time from supplied parameters.
See the full Set
overload for the remarks about DST
.
hour (int) –
minute (int) –
second (int) –
millisec (int) –
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.
jdn (float) –
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 IsValid
will return False
.
timet (int) –
SetTm
(self, tm)¶Sets the date and time from the broken down representation in the ` wx.DateTime.Tm
` structure.
tm (wx.DateTime.Tm) –
SetCountry
(country)¶Sets the country to use by default.
This setting influences the DST
calculations, date formatting and other things.
country (Country) –
See also
SetDay
(self, day)¶Sets the day without changing other date components.
day (int) –
SetFromDOS
(self, ddt)¶Sets the date from the date and time in DOS
format.
ddt (long) –
SetHour
(self, hour)¶Sets the hour without changing other date components.
hour (int) –
SetMillisecond
(self, millisecond)¶Sets the millisecond without changing other date components.
millisecond (int) –
SetMinute
(self, minute)¶Sets the minute without changing other date components.
minute (int) –
SetMonth
(self, month)¶Sets the month without changing other date components.
month (DateTime.Month) –
SetSecond
(self, second)¶Sets the second without changing other date components.
second (int) –
SetToCurrent
(self)¶Sets the date and time of to the current values.
Same as assigning the result of wx.Now
to this object.
SetToLastMonthDay
(self, month=Inv_Month, year=Inv_Year)¶Sets the date to the last day in the specified month (the current one by default).
month (DateTime.Month) –
year (int) –
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
.
weekday (DateTime.WeekDay) –
month (DateTime.Month) –
year (int) –
bool
SetToNextWeekDay
(self, weekday)¶Sets the date so that it will be the first weekday following the current date.
weekday (DateTime.WeekDay) –
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.
weekday (DateTime.WeekDay) –
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.
weekday (DateTime.WeekDay) –
n (int) –
month (DateTime.Month) –
year (int) –
bool
True
if the date was modified successfully, False
otherwise 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.
weekday (DateTime.WeekDay) –
flags (WeekFlags) –
The reference to the modified object itself.
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 GetWeekOfYear
for the explanation of how the year weeks are counted.
year (int) –
numWeek (int) –
weekday (DateTime.WeekDay) –
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-366
for the leap years and 1-365
for the other ones.
yday (int) –
The reference to the modified object itself.
SetYear
(self, year)¶Sets the year without changing other date components.
year (int) –
Subtract
(self, *args, **kw)¶Subtract (self, diff)
Subtracts the given time span from this object.
diff (wx.TimeSpan) –
Subtract (self, diff)
Subtracts the given date span from this object.
diff (wx.DateSpan) –
Subtract (self, dt)
Subtracts another date from this one and returns the difference between them as a wx.TimeSpan.
dt (wx.DateTime) –
ToTimezone
(self, tz, noDST=False)¶Transform the date to the given time zone.
If noDST is True
, no DST
adjustments will be made.
If tz parameter is wx.DateTime.Local
, no adjustment is performed.
tz (wx.DateTime.TimeZone) –
noDST (bool) –
The date adjusted by the different between the local and the given time zones.
ToUTC
(self, noDST=False)¶This is the same as calling ToTimezone
with the argument GMT0
.
noDST (bool) –
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).
See also
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.
See also
wx.Now
, GetUTCTimeMillis
__repr__
(self)¶__str__
(self)¶DayOfYear
¶See GetDayOfYear
JulianDayNumber
¶LastMonthDay
¶See GetLastMonthDay
ModifiedJulianDayNumber
¶RataDie
¶See GetRataDie
WeekOfMonth
¶See GetWeekOfMonth
WeekOfYear
¶See GetWeekOfYear
millisecond
¶See GetMillisecond
and SetMillisecond