如果你提供的是DateTime类型就可以直接转换,如果是字符串...
我试了一下,你提供的字符串在C#中无法直接转换成DateTime类型,可以手动转换一下.然后
Time.ToString("yyyy-MM-dd");
帮你粗劣写了下:
public string Stime2string(string str)
{
string[] strtime = str.Split(' ');
int y, d, m;
y = Convert.ToInt32(strtime[5]);
d = Convert.ToInt32(strtime[2]);
switch (strtime[1])
{
case "Jan": m = 1; break;
case "Feb": m = 2; break;
case "Mar": m = 3; break;
case "Apr": m = 4; break;
case "May": m = 5; break;
case "June": m = 6; break;
case "July": m = 7; break;
case "Aug": m = 8; break;
case "Sept": m = 9; break;
case "Oct": m = 10; break;
case "Nov": m = 11; break;
case "Dec": m = 12; break;
default: m = 1; break;
}
DateTime t = new DateTime(y, m, d);
return t.ToString("yyyy-MM-dd");
}
两种方法:
string.Format("{0:yyyy-MM-dd}",t.ArriveTime);
ArriveTime.year.ToString()+"-"+ArriveTime.Month.ToString()+"-"+ArriveTime.Day.ToString();
在后面加上 .ToString ("yyyy-MM-dd"); 即可
DateTime.Now.ToString().Split(new char {' '})[0]
dateTime.toshortdatestring();