我有 Windows 窗体 dateTimePicker。例如,我只想取年份的最后 3 位数字:如果选择的日期是 01.01.2016,我希望将其读作 0101016 我尝试使用的代码无法正常工作
string theDate = dateTimePicker1.Value.ToString("ddMMyyy");
当我输入 ddMMyyyy 时,它看起来像这样:01012016 没关系, 当我放 ddMMyy 时,它给出了这个 010116 什么也可以 但我需要它给我年份的最后 3 位数字,当我输入 ddMMyyy 时它不起作用:/
最佳答案
DateTime dateTime = dateTimePicker1.Value;
string theDate = dateTime.ToString("ddMM") + dateTime.Year.ToString("D4").Substring(1);
关于c# - 如何只取年份的最后 3 位数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35565767/