从DateTimePicker只获得一年

时间:2017-09-30 18:49:49

标签: winforms datetimepicker

我有一个DateTimePicker名为dtProcurationDate,它将日期显示为自定义格式yyyy/M/d ..现在我只想用代码获取它的年份

string year = dtProcurationDate.Value.Year.ToString();

也尝试了

this.dtProcurationDate.CustomFormat = "yyyy";
string year = dtProcurationDate.Value.Year.ToString();

但它给了我一个空值..

1 个答案:

答案 0 :(得分:1)

//syntax is datetimepicker.Value.Year

int year = dtProcurationDate.Value.Year; //your case