我有一个DateTime
选择器到达时间添加到列表中,我对此2个问题:日期时间选择器C#格式
- 我怎样才能得到它显示的日期一样
12-Jan-2012
而不是12/01/12
? - 我怎样才能让它显示日期后的时间,但不是当前时间,因为这是什么显示atm。
我当前的代码是不是很先进的只是:
theVisit.ArrivalTime = DateTimePicker1.Value
我有一个DateTime
选择器到达时间添加到列表中,我对此2个问题:日期时间选择器C#格式
12-Jan-2012
而不是12/01/12
?我当前的代码是不是很先进的只是:
theVisit.ArrivalTime = DateTimePicker1.Value
像这样的东西能显示日期和时间:
DateTimePicker1.Value.ToString("d-MMM-yyyy hh:mm:ss");
若要覆盖默认的DateTimePicker设置,你可以做这个:
DateTimePicker1.Format = DateTimePickerFormat.Custom;
DateTimePicker1.CustomFormat = "d-MMM-yyyy hh:mm:ss";
你可以显示一个不同的时间通过修改格式字符串,例如:
DateTimePicker1.CustomFormat = "d-MMM-yyyy 12:00:00";
甚至
DateTime otherTime = DateTime.Now;
DateTimePicker1.CustomFormat = "d-MMM-yyyy " + otherTime.ToString("hh:mm:ss");
你要找的日期时间格式的字符串。他们在MSDN上有一篇很棒的文章。 有两种类型:
您可以使用这些构建日期时间要看你怎么想它。 对于你的榜样,你可以使用:
DateTimePicker1.Value.ToString("dd-MMM-yyyy hh:mm:ss")
对于它在拾取该格式显示,设置如下
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "dd-MMM-yyyy hh:mm:ss";
第一属性,改变如何你的DateTimePicker显示DateTime是否:
DateTimePicker1.CustomFormat = "d-MMM-yyyy hh:mm:ss";
DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
您的代码:
theVisit.ArrivalTime = DateTimePicker1.Value;
不会改变,因为DateTimePicker1.Value
没有任何区别,只是根据您的格式显示。
如果您希望控件显示一个特定的时间(而不是当前的时间),你必须给那些重视控制:
DateTimePicker1.Value = new DateTime(2012, 12, 21, 23, 59, 59);
否则,它会显示当前时间,创作形式。
@嘿,我得到的错误不能隐式地将类型字符串转换为system.datetime –
TAM