如何将Datetimepicker设置为仅在月份和年份格式下显示?

25

我如何将 Datetimepicker 的格式设置为 MM/YYYY?


1
查看答案并在此处查看;http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm - Lost_In_Library
1
可能是[寻找一个用于.NET WinForm的月/年选择器控件]的重复问题(https://dev59.com/NrvxzYgBFxS5KdRjnTxC)。 - Rowland Shaw
4个回答

57

使用DateTimerPicker.Format属性。查看MSDN

public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MM/yyyy";
}

16

您可以按照以下方式使用DateTimerPicker.Format属性:

DateTimerPicker.Format = DateTimePickerFormat.Custom;
DateTimerPicker.CustomFormat = "MMMM yyyy";
DateTimerPicker.ShowUpDown = true;

注意: DateTimerPicker.ShowUpDown = true;是用于使日历不可见的。


5
这将为您提供更多选项以使用不同的格式显示日期。
DateTimerPicker.Format = DateTimePickerFormat.Custom;
DateTimerPicker.CustomFormat = "MM/yyyy"; // this line gives you only the month and year.
DateTimerPicker.ShowUpDown = true;

以下是在Windows应用程序C#的日期时间选择器控件上仅显示日期的不同格式:
DateTimerPicker.CustomFormat = "MMMM yyyy";

上述代码将显示完整的月份名称和年份,例如“2018年8月”。
DateTimerPicker.CustomFormat = "MMMM yyyy";

上述代码将显示完整的月份名称、日期和年份,例如“2018年8月8日”。
DateTimerPicker.CustomFormat = "dd MM yyyy";

这行代码将以无斜杠的格式给出指定日期 "08 08 2018"

DateTimerPicker.CustomFormat = "dd/MM/yyyy";

这行代码将会给日期“08/08/2018”添加更具体的格式。

DateTimerPicker.CustomFormat = "dd/MMM/yyyy";

这行代码以“08/Aug/2018”的格式给出日期。


-3

这行代码对我有用:

DateTimePicker1.Value.ToString("MMMM dd yyyy")

输出结果为:2019年8月


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接