时间字符串:Thu Jan 20 13:32:44 +0800 2011,在C#中的要怎么转换为yyyy-MM-dd hh:mm 这样的时间格式
如果你提供的是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");
}