C# 如何将 Datetimepicker 设置为仅月和年格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10137022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 12:35:29  来源:igfitidea点击:

How to set Datetimepicker to Month and Year only format?

c#datetimepicker

提问by asdasdad

How can I set the Datetimepicker-Format to MM/YYYY?

如何将Datetimepicker-Format设置为 MM/YYYY?

采纳答案by ABH

Use DateTimerPicker.Formatproperty. Check MSDN

使用DateTimerPicker.Format财产。检查MSDN

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

回答by Md. Shafiqur Rahman

You can use DateTimerPicker.Formatproperty as following:

您可以使用DateTimerPicker.Format以下属性:

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

Note: DateTimerPicker.ShowUpDown = true;is for making the calendar not visible

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

回答by Gopi P

This will give you some more options to display date with diff formats.

这将为您提供更多选项来以差异格式显示日期。

DateTimerPicker.Format = DateTimePickerFormat.Custom;
DateTimerPicker.CustomFormat = "MM/yyyy"; // this line gives you only the month and year.
DateTimerPicker.ShowUpDown = true;

Below are the different formats to display date alone on the date time picker control of the Windows applciation C#

以下是在 Windows 应用程序 C# 的日期时间选择器控件上单独显示日期的不同格式

DateTimerPicker.CustomFormat = "MMMM yyyy";

The above code will display the full month name and year like "August 2018"

上面的代码将显示完整的月份名称和年份,如“August 2018”

DateTimerPicker.CustomFormat = "MMMM yyyy";

The above code will display the full month name, date and year like "08 August 2018"

上面的代码将显示完整的月份名称、日期和年份,如“08 August 2018”

DateTimerPicker.CustomFormat = "dd MM yyyy";

This line will give the date in the specified format with out forward slash "08 08 2018"

此行将以指定格式给出日期,不带正斜杠“08 08 2018”

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

This line will give more specific format to the date "08/08/2018"

此行将为日期“08/08/2018”提供更具体的格式

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

This line give date in the format of "08/Aug/2018"

此行以“08/Aug/2018”格式给出日期

回答by Mikee Agstn

This line worked for me

这条线对我有用

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

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

output: August 2019

产出:2019 年 8 月