The date & time editor renders a control for setting dates and/or time values. By default, the editor renders a date input with a calendar control. Optionally, time input can be rendered as well.
The date & time editor is the default editor for DateTime
property types. The editor can also be used for string properties, in which case the property will be set to the DateTime.ToString()
value.
Usage
The date & time editor is the default editor for DateTime
properties. You can set additional configuration through the DateTimeEditorAttribute
.
Style
You can set one of the following styles of the editor through the Style
property of the DateTimeEditorAttribute
:
DateTimeEditorStyle.Date
: renders a date-only input with calendar dropdown (default).DateTimeEditorStyle.DateTime
: renders a date/time input with calendar + time dropdown.DateTimeEditorStyle.Time
: renders a time-only input with time dropdown.
Example
[Page]
public class ContentPage: IContentType
{
// Uses a date-only editor by default
public DateTime PublicationDate { get; set; }
// Specify a nullable type to make the value optional.
public DateTime? EndDate { get; set; }
// Render date/time editor. Values are saved as Ticks.
[DateTimeEditor(Style = DateTimeEditorStyle.DateTime)]
public long? TransactionDateTimeTicks { get; set; }
// Render time editor (without date component).
[DateTimeEditor(Style = DateTimeEditorStyle.Time)]
public DateTime ClosingTime { get; set; }
}