Version: 3.2.6
Loading...
Searching...
No Matches
wxDateTime Class Reference

#include <wx/datetime.h>

Detailed Description

wxDateTime class represents an absolute moment in time.

The type wxDateTime_t is typedefed as unsigned short and is used to contain the number of years, hours, minutes, seconds and milliseconds.

Global constant ::wxDefaultDateTime and synonym for it wxInvalidDateTime are defined. This constant will be different from any valid wxDateTime object.

Static Functions

All static functions either set or return the static variables of wxDateSpan (the country), return the current moment, year, month or number of days in it, or do some general calendar-related actions.

Please note that although several function accept an extra Calendar parameter, it is currently ignored as only the Gregorian calendar is supported. Future versions will support other calendars.

Date Formatting and Parsing

The date formatting and parsing functions convert wxDateTime 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 char pointer is returned. Finally, if the input parameter is a wxString, a narrow char pointer is also returned for backwards compatibility but there is also an additional argument of wxString::const_iterator type in which, if it is not NULL, an iterator pointing to the end of the scanned string part is returned.

Library:  wxBase
Category:  Data Structures

Predefined objects/pointers:

  • ::wxDefaultDateTime
See also
Date and Time, wxTimeSpan, wxDateSpan, wxCalendarCtrl