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 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
__init__ |
Default constructor. |
Add |
Adds the given date span to this object. |
ConvertYearToBC |
Converts the year in absolute notation (i.e. a number which can be negative, positive or zero) to the year in BC/AD notation. |
DiffAsDateSpan |
Returns the difference between this object and dt as a wx.DateSpan. |
Format |
This function does the same as the standard ANSI C strftime(3) function (http://www.cplusplus.com/reference/clibrary/ctime/strftime.html). |
FormatDate |
Identical to calling Format with "%x" argument (which means “preferred date representation for the current locale”). |
FormatISOCombined |
Returns the combined date-time representation in the ISO 8601 format "YYYY-MM-DDTHH:MM:SS" . |
FormatISODate |
This function returns the date representation in the ISO 8601 format "YYYY-MM-DD" . |
FormatISOTime |
This function returns the time representation in the ISO 8601 format "HH:MM:SS" . |
FormatTime |
Identical to calling Format with "%X" argument (which means “preferred time representation for the current locale”). |
FromDMY |
Construct a DateTime using the supplied parameters. |
FromHMS |
Construct a DateTime equal to Today () with the time set to the supplied parameters. |
FromJDN |
Construct a DateTime from a Julian Day Number. |
FromTimeT |
Construct a DateTime from a C time_t value, the number of seconds since the epoch. |
FromTimezone |
Transform the date from the given time zone to the local one. |
GetAmPmStrings |
Returns the translations of the strings AM and PM used for time formatting for the current locale. |
GetAsDOS |
Returns the date and time in DOS format. |
GetBeginDST |
Get the beginning of DST for the given country in the given year (current one by default). |
GetCentury |
Returns the century of this date. |
GetCountry |
Returns the current default country. |
GetCurrentMonth |
Get the current month in given calendar (only Gregorian is currently supported). |
GetCurrentYear |
Get the current year in given calendar (only Gregorian is currently supported). |
GetDateOnly |
Returns the object having the same date component as this one but time of 00:00:00. |
GetDay |
Returns the day in the given timezone (local one by default). |
GetDayOfYear |
Returns the day of the year (in 1-366 range) in the given timezone (local one by default). |
GetEndDST |
Returns the end of DST for the given country in the given year (current one by default). |
GetEnglishMonthName |
Return the standard English name of the given month. |
GetEnglishWeekDayName |
Return the standard English name of the given week day. |
GetHour |
Returns the hour in the given timezone (local one by default). |
GetJDN |
Synonym for GetJulianDayNumber . |
GetJulianDayNumber |
Returns the JDN corresponding to this date. |
GetLastMonthDay |
Returns the copy of this object to which SetToLastMonthDay was applied. |
GetLastWeekDay |
Returns the copy of this object to which SetToLastWeekDay was applied. |
GetMJD |
Synonym for GetModifiedJulianDayNumber . |
GetMillisecond |
Returns the milliseconds in the given timezone (local one by default). |
GetMinute |
Returns the minute in the given timezone (local one by default). |
GetModifiedJulianDayNumber |
Returns the “Modified Julian Day Number” (MJD ) which is, by definition, is equal to JDN - 2400000.5. |
GetMonth |
Returns the month in the given timezone (local one by default). |
GetMonthName |
Gets the full (default) or abbreviated name of the given month. |
GetNextWeekDay |
Returns the copy of this object to which SetToNextWeekDay was applied. |
GetNumberOfDays |
Returns the number of days in the given month of the given year. |
GetPrevWeekDay |
Returns the copy of this object to which SetToPrevWeekDay was applied. |
GetRataDie |
Return the Rata Die number of this date. |
GetSecond |
Returns the seconds in the given timezone (local one by default). |
GetTicks |
Returns the number of seconds since Jan 1, 1970 UTC . |
GetTimeNow |
Returns the current time. |
GetTm |
Returns broken down representation of the date and time. |
GetWeekDay |
Returns the week day in the given timezone (local one by default). |
GetWeekDayInSameWeek |
Returns the copy of this object to which SetToWeekDayInSameWeek was applied. |
GetWeekDayName |
Gets the full (default) or abbreviated name of the given week day. |
GetWeekOfMonth |
Returns the ordinal number of the week in the month (in 1-5 range). |
GetWeekOfYear |
Returns the number of the week of the year this date is in. |
GetYear |
Returns the year in the given timezone (local one by default). |
GetYearDay |
Returns the copy of this object to which SetToYearDay was applied. |
IsBetween |
Returns True if IsStrictlyBetween is True or if the date is equal to one of the limit values. |
IsDST |
Returns True if the DST is applied for this date in the given country. |
IsDSTApplicable |
Returns True if DST was used in the given year (the current one by default) in the given country. |
IsEarlierThan |
Returns True if this date precedes the given one. |
IsEqualTo |
Returns True if the two dates are strictly identical. |
IsEqualUpTo |
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. |
IsLaterThan |
Returns True if this date is later than the given one. |
IsLeapYear |
Returns True if the year is a leap one in the specified calendar. |
IsSameDate |
Returns True if the date is the same without comparing the time parts. |
IsSameTime |
Returns True if the time is the same (although dates may differ). |
IsStrictlyBetween |
Returns True if this date lies strictly between the two given dates. |
IsValid |
Returns True if the object represents a valid time moment. |
IsWestEuropeanCountry |
This function returns True if the specified (or default) country is one of Western European ones. |
IsWorkDay |
Returns True is this day is not a holiday in the given country. |
MakeFromTimezone |
Same as FromTimezone but modifies the object in place. |
MakeTimezone |
Modifies the object in place to represent the date in another time zone. |
MakeUTC |
This is the same as calling MakeTimezone with the argument GMT0 . |
Now |
Returns the object corresponding to the current time. |
ParseDate |
This function is like ParseDateTime , but it only allows the date to be specified. |
ParseDateTime |
Parses the string datetime containing the date and time in free format. |
ParseFormat |
This function parses the string date according to the given format. |
ParseISOCombined |
This function parses the string containing the date and time in ISO 8601 combined format "YYYY-MM-DDTHH:MM:SS" . |
ParseISODate |
This function parses the date in ISO 8601 format "YYYY-MM-DD" . |
ParseISOTime |
This function parses the time in ISO 8601 format "HH:MM:SS" . |
ParseRfc822Date |
Parses the string date looking for a date formatted according to the RFC 822 in it. |
ParseTime |
This functions is like ParseDateTime , but only allows the time to be specified in the input string. |
ResetTime |
Reset time to midnight (00:00:00) without changing the date. |
Set |
Sets the date and time from the parameters. |
SetHMS |
Sets the date to be equal to Today and the time from supplied parameters. |
SetJDN |
Sets the date from the so-called Julian Day Number. |
SetTimeT |
Constructs the object from timet value holding the number of seconds since Jan 1, 1970 UTC . |
SetTm |
Sets the date and time from the broken down representation in the ` wx.DateTime.Tm ` structure. |
SetCountry |
Sets the country to use by default. |
SetDay |
Sets the day without changing other date components. |
SetFromDOS |
Sets the date from the date and time in DOS format. |
SetHour |
Sets the hour without changing other date components. |
SetMillisecond |
Sets the millisecond without changing other date components. |
SetMinute |
Sets the minute without changing other date components. |
SetMonth |
Sets the month without changing other date components. |
SetSecond |
Sets the second without changing other date components. |
SetToCurrent |
Sets the date and time of to the current values. |
SetToLastMonthDay |
Sets the date to the last day in the specified month (the current one by default). |
SetToLastWeekDay |
The effect of calling this function is the same as of calling SetToWeekDay (-1, weekday, month, year). |
SetToNextWeekDay |
Sets the date so that it will be the first weekday following the current date. |
SetToPrevWeekDay |
Sets the date so that it will be the last weekday before the current date. |
SetToWeekDay |
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). |
SetToWeekDayInSameWeek |
Adjusts the date so that it will still lie in the same week as before, but its week day will be the given one. |
SetToWeekOfYear |
Set the date to the given weekday in the week number numWeek of the given year . |
SetToYearDay |
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). |
SetYear |
Sets the year without changing other date components. |
Subtract |
Subtracts the given time span from this object. |
ToTimezone |
Transform the date to the given time zone. |
ToUTC |
This is the same as calling ToTimezone with the argument GMT0 . |
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). |
UNow |
Returns the object corresponding to the current UTC time including the milliseconds. |
__repr__ |
|
__str__ |
DayOfYear |
See GetDayOfYear |
JDN |
See GetJDN and SetJDN |
JulianDayNumber |
See GetJulianDayNumber |
LastMonthDay |
See GetLastMonthDay |
MJD |
See GetMJD |
ModifiedJulianDayNumber |
See GetModifiedJulianDayNumber |
RataDie |
See GetRataDie |
Ticks |
See GetTicks |
WeekOfMonth |
See GetWeekOfMonth |
WeekOfYear |
See GetWeekOfYear |
day |
See GetDay and SetDay |
hour |
See GetHour and SetHour |
millisecond |
See GetMillisecond and SetMillisecond |
minute |
See GetMinute and SetMinute |
month |
See GetMonth and SetMonth |
second |
See GetSecond and SetSecond |
year |
See GetYear and SetYear |
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.
Parameters: | date (wx.DateTime) – |
---|
__init__ (self, day, month, year=Inv_Year, hour=0, minute=0, second=0, millisec=0)
Same as Set
.
Parameters: |
|
---|
Add
(self, *args, **kw)¶Add (self, diff)
Adds the given date span to this object.
Parameters: | diff (wx.DateSpan) – |
---|---|
Return type: | wx.DateTime |
Add (self, diff)
Adds the given time span to this object.
Parameters: | diff (wx.TimeSpan) – |
---|---|
Return type: | 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.
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 to find the number of entire years, months, weeks and days between dt and this date.
Parameters: | dt (wx.DateTime) – |
---|---|
Return type: | wx.DateSpan |
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 (http://www.cplusplus.com/reference/clibrary/ctime/strftime.html).
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.
Parameters: |
|
---|---|
Return type: |
|
See also
FormatDate
(self)¶Identical to calling Format
with "%x"
argument (which means “preferred date representation for the current locale”).
Return type: | 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.
Parameters: | sep (int) – |
---|---|
Return type: | string |
See also
FormatISODate
(self)¶This function returns the date representation in the ISO
8601 format "YYYY-MM-DD"
.
Return type: | string |
---|
FormatISOTime
(self)¶This function returns the time representation in the ISO
8601 format "HH:MM:SS"
.
Return type: | string |
---|
FormatTime
(self)¶Identical to calling Format
with "%X"
argument (which means “preferred time representation for the current locale”).
Return type: | string |
---|
FromDMY
(day, month, year=Inv_Year, hour=0, minute=0, second=0, millisecond=0)¶Construct a DateTime
using the supplied parameters.
Return type: | wx.DateTime |
---|
FromHMS
(hour, minute=0, second=0, millisecond=0)¶Construct a DateTime
equal to Today
() with the time set to the supplied parameters.
Return type: | wx.DateTime |
---|
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.
Return type: | wx.DateTime |
---|
FromTimeT
(timet)¶Construct a DateTime
from a C time_t
value, the number of seconds since the epoch.
Return type: | wx.DateTime |
---|
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.
Notice using wx.DateTime.Local
for tz parameter doesn’t really make sense and may result in unexpected results as it will return a different object when DST
is in use and noDST has its default value of False
.
Parameters: |
|
---|---|
Return type: | |
Returns: | 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.
Return type: | tuple |
---|---|
Returns: | ( am, pm ) |
GetAsDOS
(self)¶Returns the date and time in DOS
format.
Return type: | 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.
Parameters: |
|
---|---|
Return type: |
See also
GetCentury
(self, tz=Local)¶Returns the century of this date.
Parameters: | tz (wx.DateTime.TimeZone) – |
---|---|
Return type: | int |
GetCountry
()¶Returns the current default country.
The default country is used for DST
calculations, for example.
Return type: | wx.DateTime.Country |
---|
See also
GetCurrentMonth
(cal=Gregorian)¶Get the current month in given calendar (only Gregorian is currently supported).
Parameters: | cal (Calendar) – |
---|---|
Return type: | wx.DateTime.Month |
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: | wx.DateTime |
---|
New 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: | intshort |
GetDayOfYear
(self, tz=Local)¶Returns the day of the year (in 1-366
range) in the given timezone (local one by default).
Parameters: | tz (wx.DateTime.TimeZone) – |
---|---|
Return type: | 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).
Parameters: |
|
---|---|
Return type: |
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.
Parameters: |
|
---|---|
Return type: |
|
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.
Parameters: |
|
---|---|
Return type: |
|
New in version 2.9.0.
See also
GetHour
(self, tz=Local)¶Returns the hour in the given timezone (local one by default).
Parameters: | tz (wx.DateTime.TimeZone) – |
---|---|
Return type: | intshort |
GetJDN
(self)¶Synonym for GetJulianDayNumber
.
Return type: | float |
---|
GetJulianDayNumber
(self)¶Returns the JDN
corresponding 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 SetToLastMonthDay
was applied.
Parameters: |
|
---|---|
Return type: |
GetLastWeekDay
(self, weekday, month=Inv_Month, year=Inv_Year)¶Returns the copy of this object to which SetToLastWeekDay
was applied.
Parameters: |
|
---|---|
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: | intshort |
GetMinute
(self, tz=Local)¶Returns the minute in the given timezone (local one by default).
Parameters: | tz (wx.DateTime.TimeZone) – |
---|---|
Return type: | 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.
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: | wx.DateTime.Month |
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.
Parameters: |
|
---|---|
Return type: |
|
See also
GetNextWeekDay
(self, weekday)¶Returns the copy of this object to which SetToNextWeekDay
was applied.
Parameters: | weekday (DateTime.WeekDay) – |
---|---|
Return type: | wx.DateTime |
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: |
|
---|---|
Return type: | intshort |
GetPrevWeekDay
(self, weekday)¶Returns the copy of this object to which SetToPrevWeekDay
was applied.
Parameters: | weekday (DateTime.WeekDay) – |
---|---|
Return type: | wx.DateTime |
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: | intshort |
GetTicks
(self)¶Returns the number of seconds since Jan 1, 1970 UTC
.
An assert failure will occur if the date is not in the range covered by time_t
type, use GetValue() if you work with dates outside of it.
Return type: | int |
---|
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: | wx.DateTime.Tm |
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: | wx.DateTime.WeekDay |
GetWeekDay (self, weekday, n=1, month=Inv_Month, year=Inv_Year)
Returns the copy of this object to which SetToWeekDay
was applied.
Parameters: |
|
---|---|
Return type: |
GetWeekDayInSameWeek
(self, weekday, flags=Monday_First)¶Returns the copy of this object to which SetToWeekDayInSameWeek
was applied.
Parameters: |
|
---|---|
Return type: |
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.
Parameters: |
|
---|---|
Return type: |
|
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.
Parameters: |
|
---|---|
Return type: | 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.
Parameters: |
|
---|---|
Return type: | intshort |
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 SetToYearDay
was applied.
Parameters: | yday (int) – |
---|---|
Return type: | wx.DateTime |
IsBetween
(self, t1, t2)¶Returns True
if IsStrictlyBetween
is True
or if the date is equal to one of the limit values.
Parameters: |
|
---|---|
Return type: | bool |
See also
IsDST
(self, country=Country_Default)¶Returns True
if the DST
is applied for this date in the given country.
Parameters: | country (Country) – |
---|---|
Return type: | 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.
Parameters: |
|
---|---|
Return type: | bool |
IsEarlierThan
(self, datetime)¶Returns True
if this date precedes the given one.
Parameters: | datetime (wx.DateTime) – |
---|---|
Return type: | bool |
IsEqualTo
(self, datetime)¶Returns True
if the two dates are strictly identical.
Parameters: | datetime (wx.DateTime) – |
---|---|
Return type: | 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.
Parameters: |
|
---|---|
Return type: | bool |
IsLaterThan
(self, datetime)¶Returns True
if this date is later than the given one.
Parameters: | datetime (wx.DateTime) – |
---|---|
Return type: | 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.
Parameters: |
|
---|---|
Return type: | bool |
IsSameDate
(self, dt)¶Returns True
if the date is the same without comparing the time parts.
Parameters: | dt (wx.DateTime) – |
---|---|
Return type: | bool |
IsSameTime
(self, dt)¶Returns True
if the time is the same (although dates may differ).
Parameters: | dt (wx.DateTime) – |
---|---|
Return type: | bool |
IsStrictlyBetween
(self, t1, t2)¶Returns True
if this date lies strictly between the two given dates.
Parameters: |
|
---|---|
Return type: | bool |
See also
IsValid
(self)¶Returns True
if the object represents a valid time moment.
Return type: | 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.
Parameters: | country (Country) – |
---|---|
Return type: | bool |
IsWorkDay
(self, country=Country_Default)¶Returns True
is this day is not a holiday in the given country.
Parameters: | country (Country) – |
---|---|
Return type: | bool |
MakeFromTimezone
(self, tz, noDST=False)¶Same as FromTimezone
but modifies the object in place.
Parameters: |
|
---|---|
Return type: |
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.
Parameters: |
|
---|---|
Return type: |
MakeUTC
(self, noDST=False)¶This is the same as calling MakeTimezone
with the argument GMT0
.
Parameters: | noDST (bool) – |
---|---|
Return type: | wx.DateTime |
Now
()¶Returns the object corresponding to the current time.
Example:
now = wx.DateTime.Now()
print "Current time in Paris:\t%s\n"%(now.Format("%c", wx.DateTime.CET))
Return type: | wx.DateTime |
---|
Note
This function is accurate up to seconds. UNow
can 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 ParseFormat
for the description of function parameters and return value.
Parameters: | date (string) – |
---|---|
Return type: | 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.
Parameters: | datetime (string) – |
---|---|
Return type: | int |
ParseFormat
(self, *args, **kw)¶ParseFormat (self, date, format, dateDef)
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 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
Parameters: |
|
---|---|
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 ParseFormat
method works the same, but with missing values filled in from Today
.
Parameters: |
|
---|---|
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 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.
Parameters: |
|
---|---|
Return type: | bool |
Returns: |
|
ParseISODate
(self, date)¶This function parses the date in ISO
8601 format "YYYY-MM-DD"
.
Parameters: | date (string) – |
---|---|
Return type: | bool |
Returns: | 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"
.
Parameters: | date (string) – |
---|---|
Return type: | bool |
Returns: | 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.
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 ParseFormat
for 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: | wx.DateTime |
---|
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.
Parameters: |
|
---|---|
Return type: |
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
.
Parameters: |
|
---|---|
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: | wx.DateTime |
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
.
Parameters: | timet (int) – |
---|---|
Return type: | wx.DateTime |
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: | wx.DateTime |
SetCountry
(country)¶Sets the country to use by default.
This setting influences the DST
calculations, date formatting and other things.
Parameters: | country (Country) – |
---|
See also
SetDay
(self, day)¶Sets the day without changing other date components.
Parameters: | day (int) – |
---|---|
Return type: | wx.DateTime |
SetFromDOS
(self, ddt)¶Sets the date from the date and time in DOS
format.
Parameters: | ddt (long) – |
---|---|
Return type: | wx.DateTime |
SetHour
(self, hour)¶Sets the hour without changing other date components.
Parameters: | hour (int) – |
---|---|
Return type: | wx.DateTime |
SetMillisecond
(self, millisecond)¶Sets the millisecond without changing other date components.
Parameters: | millisecond (int) – |
---|---|
Return type: | wx.DateTime |
SetMinute
(self, minute)¶Sets the minute without changing other date components.
Parameters: | minute (int) – |
---|---|
Return type: | wx.DateTime |
SetMonth
(self, month)¶Sets the month without changing other date components.
Parameters: | month (DateTime.Month) – |
---|---|
Return type: | wx.DateTime |
SetSecond
(self, second)¶Sets the second without changing other date components.
Parameters: | second (int) – |
---|---|
Return type: | wx.DateTime |
SetToCurrent
(self)¶Sets the date and time of to the current values.
Same as assigning the result of wx.Now
to this object.
Return type: | wx.DateTime |
---|
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: |
|
---|---|
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: |
|
---|---|
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: | wx.DateTime |
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: | wx.DateTime |
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(2, DateTime.Wed) will set the date to the second Wednesday in the current month and SetToWeekDay(-1, wx.DateTime.Sun
) will set the date to the last Sunday in the current month.
Parameters: |
|
---|---|
Return type: | bool |
Returns: |
|
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: |
|
---|---|
Return type: | |
Returns: | 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.
Parameters: |
|
---|---|
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-366
for the leap years and 1-365
for the other ones.
Parameters: | yday (int) – |
---|---|
Return type: | wx.DateTime |
Returns: | The reference to the modified object itself. |
SetYear
(self, year)¶Sets the year without changing other date components.
Parameters: | year (int) – |
---|---|
Return type: | wx.DateTime |
Subtract
(self, *args, **kw)¶Subtract (self, diff)
Subtracts the given time span from this object.
Parameters: | diff (wx.TimeSpan) – |
---|---|
Return type: | wx.DateTime |
Subtract (self, diff)
Subtracts the given date span from this object.
Parameters: | diff (wx.DateSpan) – |
---|---|
Return type: | wx.DateTime |
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: | wx.TimeSpan |
ToTimezone
(self, tz, noDST=False)¶Transform the date to the given time zone.
If noDST is True
, no DST
adjustments will be made.
Notice that, as with FromTimezone
, using wx.DateTime.Local
as tz doesn’t really make sense and may return a different object when DST
is in effect and noDST is False
.
Parameters: |
|
---|---|
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 ToTimezone
with the argument GMT0
.
Parameters: | noDST (bool) – |
---|---|
Return type: | wx.DateTime |
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: | wx.DateTime |
---|
See also
UNow
()¶Returns the object corresponding to the current UTC
time including the milliseconds.
Notice that unlike wx.Now
, this method creates a wx.DateTime object corresponding to UTC
, not local, time.
Return type: | wx.DateTime |
---|
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