c#中关于日期转换的方法,求指导,求教育,我想只查询到月,应该怎么改啊!!!!
private string date()
{
string date = this.dateTimePicker1.Text.Replace('年', '-').Replace('月', '-').Replace('日', ' ');
//string date = this.dateTimePicker1.Text.Replace('年', '-').Replace('月', ' ');
string dateNew = string.Empty;
char[] C ={ '-' };
string[] dateinfo = date.Split(C);
if (dateinfo[1].Trim().ToString().Length <= 1)
{
dateNew += dateinfo[0].ToString() + "-0" + dateinfo[1].ToString();
}
else
{
dateNew += dateinfo[0].ToString() + "-" + dateinfo[1].ToString();
}
if (dateinfo[2].Trim().ToString().Length <= 1)
{
dateNew += "-0" + dateinfo[2].ToString();
}
else
{
dateNew += "-" + dateinfo[2].ToString();
}
return dateNew;
}