Table Of Contents

Previous topic

DateSpan

Next topic

Dialog

This Page

phoenix_title DateTime

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 DefaultDateTime and synonym for it InvalidDateTime are defined. This constant will be different from any valid DateTime object.

phoenix_title Static Functions

All static functions either set or return the static variables of 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.

phoenix_title Date Formatting and Parsing

The date formatting and parsing functions convert 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 type in which, if it is not None, an iterator pointing to the end of the scanned string part is returned.


class_hierarchy Inheritance Diagram

Inheritance diagram for class DateTime

Inheritance diagram of DateTime


method_summary Methods Summary

__init__ Default constructor.
Add Adds the given date span to this object.
ConvertYearToBC Converts the year in absolute notation (i.e.
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.
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.
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.
SetTm Sets the date and time from the broken down representation in the `` 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.
UNow Returns the object corresponding to the current UTC time including the milliseconds.
__repr__  
__str__  

api Class API



class DateTime(object)

DateTime class represents an absolute moment in time.

Possible constructors:

DateTime()

DateTime(date)

DateTime(day, month, year=Inv_Year, hour=0, minute=0, second=0,
         millisec=0)

Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.

Use one of the Set functions to initialize the object later.



__init__ (self, date)

Copy constructor.

Parameters:date (DateTime) –



__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) –





Add(self, *args, **kw)

overload Overloaded Implementations:



Add (self, diff)

Adds the given date span to this object.

Parameters:diff (DateSpan) –
Return type: DateTime



Add (self, diff)

Adds the given time span to this object.

Parameters:diff (TimeSpan) –
Return type: DateTime





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 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


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.

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:

string

See also

ParseFormat



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


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


static FromDMY(day, month, year= Inv_Year, hour=0, minute=0, second=0, millisecond=0)

Construct a DateTime using the supplied parameters.

Return type: DateTime


static FromHMS(hour, minute=0, second=0, millisecond=0)

Construct a DateTime equal to Today() with the time set to the supplied parameters.

Return type: DateTime


static 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: DateTime


static FromTimeT(timet)

Construct a DateTime from a C time_t value, the number of seconds since the epoch.

Return type: 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.

Parameters:
Return type:

DateTime

Returns:

The date in the local time zone.



static 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


static 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:
  • year (int) –
  • country (Country) –
Return type:

DateTime

See also

GetEndDST



GetCentury(self, *args, **kw)

Returns the century of this date.



static GetCountry()

Returns the current default country.

The default country is used for DST calculations, for example.

Return type: Country

See also

SetCountry



static GetCurrentMonth(cal=Gregorian)

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

Parameters:cal (Calendar) –
Return type:DateTime.Month


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: DateTime

New in version 2.8.2.

See also

ResetTime



GetDay(self, tz=Local)

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

Parameters:tz (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 (TimeZone) –
Return type:intshort


static 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:
  • year (int) –
  • country (Country) –
Return type:

DateTime

See also

GetBeginDST



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 GetMonthName to retrieve the name of the month in the users current locale.

Parameters:
  • month (DateTime.Month) – One of DateTime.Jan , ..., DateTime.Dec values.
  • flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
Return type:

string

New in version 2.9.0.



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 GetWeekDayName to retrieve the name of the month in the users current locale.

Parameters:
  • weekday (DateTime.WeekDay) – One of DateTime.Sun , ..., DateTime.Sat values.
  • flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
Return type:

string

New in version 2.9.0.



GetHour(self, tz=Local)

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

Parameters:tz (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


GetLastMonthDay(self, month=Inv_Month, year=Inv_Year)

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

Parameters:
  • month (DateTime.Month) –
  • year (int) –
Return type:

DateTime



GetLastWeekDay(self, weekday, month=Inv_Month, year=Inv_Year)

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

Parameters:
  • weekday (DateTime.WeekDay) –
  • month (DateTime.Month) –
  • year (int) –
Return type:

DateTime



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 (TimeZone) –
Return type:intshort


GetMinute(self, tz=Local)

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

Parameters:tz (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 (TimeZone) –
Return type:DateTime.Month


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 GetEnglishMonthName to get the untranslated name if necessary.

Parameters:
  • month (DateTime.Month) – One of DateTime.Jan , ..., DateTime.Dec values.
  • flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
Return type:

string

See also

GetWeekDayName



GetNextWeekDay(self, weekday)

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

Parameters:weekday (DateTime.WeekDay) –
Return type: DateTime


static GetNumberOfDays(*args, **kw)

Returns the number of days in the given month of the given year.

The only supported value for cal currently is Gregorian .



GetPrevWeekDay(self, weekday)

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

Parameters:weekday (DateTime.WeekDay) –
Return type: 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 (TimeZone) –
Return type:intshort


GetTicks(self)

Returns the number of seconds since Jan 1, 1970.

An assert failure will occur if the date is not in the range covered by time_t type.

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 (TimeZone) –
Return type:DateTime.Tm


GetWeekDay(self, *args, **kw)

overload Overloaded Implementations:



GetWeekDay (self, tz=Local)

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

Parameters:tz (TimeZone) –
Return type: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:
  • weekday (DateTime.WeekDay) –
  • n (int) –
  • month (DateTime.Month) –
  • year (int) –
Return type:

DateTime





GetWeekDayInSameWeek(self, weekday, flags=Monday_First)

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

Parameters:
  • weekday (DateTime.WeekDay) –
  • flags (WeekFlags) –
Return type:

DateTime



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 GetEnglishWeekDayName to get the untranslated name if necessary.

Parameters:
  • weekday (DateTime.WeekDay) – One of DateTime.Sun , ..., DateTime.Sat values.
  • flags (NameFlags) – Either Name_Full (default) or Name_Abbr.
Return type:

string

See also

GetMonthName



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 (TimeZone) –
Return type:int


GetYearDay(self, yday)

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

Parameters:yday (int) –
Return type: 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



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

GetBeginDST , GetEndDST



static 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:
  • year (int) –
  • country (Country) –
Return type:

bool



IsEarlierThan(self, datetime)

Returns True if this date precedes the given one.

Parameters:datetime (DateTime) –
Return type:bool


IsEqualTo(self, datetime)

Returns True if the two dates are strictly identical.

Parameters:datetime (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 (DateTime) –
Return type:bool


static 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 (DateTime) –
Return type:bool


IsSameTime(self, dt)

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

Parameters:dt (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

IsBetween



IsValid(self)

Returns True if the object represents a valid time moment.

Return type:bool


static 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 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:

DateTime



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:

DateTime



MakeUTC(self, noDST=False)

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

Parameters:noDST (bool) –
Return type: DateTime


static 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: DateTime

Note

This function is accurate up to seconds. UNow can be used if better precision is required.

See also

Today



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:bool

See also

Format



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:bool


ParseFormat(self, *args, **kw)

overload Overloaded Implementations:



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 not dt.ParseFormat(bDate, "%d-%m-%Y"):
    # This datetime format is wrong on purpose
    print "Wrong format"

elif dt.ParseFormat(bDate, "%d/%m/%Y"):
    # This is correct
    print "Format OK!", dt
Parameters:
  • date (string) – The string to be parsed.
  • format (string) – strptime()-like format string.
  • dateDef (DateTime) – Used to fill in the date components not specified in the date string.

Will be filled with the iterator pointing to the location where the parsing stopped if the function returns True. If the entire string was consumed, it is set to date.end() . Notice that this argument must be not None.

Return type:bool
Returns:True if at least part of the string was parsed successfully, False otherwise.

See also

Format



ParseFormat (self, date, format)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • date (string) –
  • format (string) –
Return type:

bool



ParseFormat (self, date)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:date (string) –
Return type:bool





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:
  • date (string) –
  • sep (int) –
Return type:

bool

Returns:

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" .

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:bool


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:bool


ResetTime(self)

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

Return type: DateTime


Set(self, *args, **kw)

Sets the date and time from the parameters.



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

Sets the date to be equal to Today and the time from supplied parameters.

Parameters:
  • hour (int) –
  • minute (int) –
  • second (int) –
  • millisec (int) –
Return type:

DateTime



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: DateTime


SetTimeT(self, timet)

Constructs the object from timet value holding the number of seconds since Jan 1, 1970.

Parameters:timet (int) –
Return type: DateTime


SetTm(self, tm)

Sets the date and time from the broken down representation in the `` DateTime.Tm `` structure.

Parameters:tm (Tm) –
Return type: DateTime


static 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

GetCountry



SetDay(self, day)

Sets the day without changing other date components.

Parameters:day (int) –
Return type: DateTime


SetFromDOS(self, ddt)

Sets the date from the date and time in DOS format.

Parameters:ddt (long) –
Return type: DateTime


SetHour(self, hour)

Sets the hour without changing other date components.

Parameters:hour (int) –
Return type: DateTime


SetMillisecond(self, millisecond)

Sets the millisecond without changing other date components.

Parameters:millisecond (int) –
Return type: DateTime


SetMinute(self, minute)

Sets the minute without changing other date components.

Parameters:minute (int) –
Return type: DateTime


SetMonth(self, month)

Sets the month without changing other date components.

Parameters:month (DateTime.Month) –
Return type: DateTime


SetSecond(self, second)

Sets the second without changing other date components.

Parameters:second (int) –
Return type: DateTime


SetToCurrent(self)

Sets the date and time of to the current values.

Same as assigning the result of Now to this object.

Return type: 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:
  • month (DateTime.Month) –
  • year (int) –
Return type:

DateTime

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: 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: 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, DateTime.Sun ) will set the date to the last Sunday in the current month.

Parameters:
  • weekday (DateTime.WeekDay) –
  • n (int) –
  • month (DateTime.Month) –
  • year (int) –
Return type:

bool

Returns:

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.

Parameters:
  • weekday (DateTime.WeekDay) –
  • flags (WeekFlags) –
Return type:

DateTime

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 GetWeekOfYear for the explanation of how the year weeks are counted.

Parameters:
  • year (int) –
  • numWeek (int) –
  • weekday (DateTime.WeekDay) –
Return type:

DateTime



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: 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: DateTime


Subtract(self, *args, **kw)

overload Overloaded Implementations:



Subtract (self, diff)

Subtracts the given time span from this object.

Parameters:diff (TimeSpan) –
Return type: DateTime



Subtract (self, diff)

Subtracts the given date span from this object.

Parameters:diff (DateSpan) –
Return type: DateTime



Subtract (self, dt)

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

Parameters:dt (DateTime) –
Return type: TimeSpan





ToTimezone(self, tz, noDST=False)

Transform the date to the given time zone.

If noDST is True, no DST adjustments will be made.

Parameters:
Return type:

DateTime

Returns:

The date in the new time zone.



ToUTC(self, noDST=False)

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

Parameters:noDST (bool) –
Return type: DateTime


static Today()

Returns the object corresponding to the midnight of the current day (i.e.

the same as Now , but the time part is set to 0).

Return type: DateTime

See also

Now



static UNow()

Returns the object corresponding to the current UTC time including the milliseconds.

Notice that unlike Now , this method creates a DateTime object corresponding to UTC, not local, time.

Return type: DateTime

See also

Now , GetUTCTimeMillis



__repr__(self)


__str__(self)

Properties



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