Export (0) Print
Expand All

DateTimePicker.Format Property

Gets or sets the format of the date and time displayed in the control.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public DateTimePickerFormat Format { get; set; }
/** @property */
public DateTimePickerFormat get_Format ()

/** @property */
public void set_Format (DateTimePickerFormat value)

public function get Format () : DateTimePickerFormat

public function set Format (value : DateTimePickerFormat)

Property Value

One of the DateTimePickerFormat values. The default is Long.

Exception typeCondition

InvalidEnumArgumentException

The value assigned is not one of the DateTimePickerFormat values.

This property determines the date/time format the date is displayed in. The date/time format is based on the user's regional settings in their operating system.

NoteNote

The Format property must be set to DateTimePickerFormat.Custom for the CustomFormat property to affect the formatting of the displayed date and time.

To display only time in a DateTimePicker, set the Format to Time, and the ShowUpDown property to false.

The following code example sets the CustomFormat property so that the DateTimePicker will display the date as "June 01, 2001 - Friday". This code assumes that an instance of a DateTimePicker control has been created on a Form.

public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}


public void SetMyCustomFormat()
{
    // Set the Format type and the CustomFormat string.
    dateTimePicker1.set_Format(DateTimePickerFormat.Custom);
    dateTimePicker1.set_CustomFormat("MMMM dd, yyyy - dddd");
} //SetMyCustomFormat

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft