如何解码datetimepicker [英] How do decode datetimepicker
问题描述
dateTimePicker1.Value.ToString()= prop.AdmissionYear;
我尝试过:
dateTimePicker1.Value.ToString()= prop.AdmissionYear;
dateTimePicker1.Value.ToString() = prop.AdmissionYear;
What I have tried:
dateTimePicker1.Value.ToString() = prop.AdmissionYear;
推荐答案
DateTimePicker类(System.Windows.Forms) [ ^ ]。
该代码有很多错误...
There are loads of things wrong with that code...
dateTimePicker1.Value.ToString() = prop.AdmissionYear;
字符串是不可变的,所以当你尝试为字符串对象分配一个新的值时,你期望发生的事情我不知道。您可以为字符串变量赋值,但不能为对象赋值。
日期不仅仅是一年:它们也有月和日。因此,您可能希望使用年份来生成一个适当的日期,该日期将在学年开始时:
Strings are immutable, so quite what you expect to happen when you try to assign a string object a new value I don;t know. You can assign a value to a string variable, but not to an object.
Dates are not just a year: they have months and days as well. So you probably want to use the year to generate a "proper" date which would be around the start of the academic year:
dateTimePicker1.Value = new DateTime(int.Parse(prop.AdmissionYear), 9, 1);
这篇关于如何解码datetimepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!