The DateEdit control supports a number of date formats classified as follows:
Predefined formats: DateEdit supports short date, long date, general date, short time, long time, scientific, percent, and several other predefined formats. You can display date and time in any of these formats by setting the FormatType property, which takes its value from FormatType enumeration.
The following image shows the DateEdit control displaying date and time in Greenwich Mean Time.
The following code snippet shows how to set the predefined formatting via code:
C# |
Copy Code
|
---|---|
//Data Formatting
dateEdit.Value = DateTime.Now;
dateEdit.FormatType = FormatType.DateAndTimeGMT;
|
Custom formats: DateEdit allows custom formatting of dates. You can specify custom formats and display dates in those formats. To enable custom formatting, set the FormatType property to CustomFormat using the FormatType enumeration. Further, to display dates in custom formats, set custom format specifiers in the CustomFormat property.
For information on custom format specifiers, see Custom Date and Time Format Strings. The DateEdit control supports majority of these format strings.
The following image shows the DateEdit control displaying date in a custom format.
The following code snippet shows how to display a date in a custom format in DateEdit.
C# |
Copy Code
|
---|---|
// specify the format type as custom format dateEdit.FormatType = FormatType.CustomFormat; // set the custom format specifier dateEdit.CustomFormat = "dddd-MM-yyyy"; |
Converting the string entered by the user to the data type is called parsing. It is the opposite of formatting. The DateEdit control allows controlling parsing through the ParseInfo property. The ParseInfo property provides access to the ParseInfo Class that contains sub-properties that control different aspects of parsing.
Though default parsing suffices in a majority of cases, you can still change many aspects of how the control parses, by expanding the ParseInfo property, changing the (Inherit) flags, and setting desired properties. By default, the same format property value is used for parsing as for formatting.