好吧,我已经醒太久了。快疯了。请有人告诉我为什么这不起作用。传入“201212120600”之类的字符串Substring(0,4)
返回“201”而不是“2012”。我的大脑正在融化。
private DateTime StringToDateTimeUTC(String s)
{
System.Diagnostics.Debug.WriteLine(s);
String syear = s.Substring(0, 4);
System.Diagnostics.Debug.WriteLine(syear);
int year = int.Parse(s.Substring(0, 4));
int month = int.Parse(s.Substring(4, 2));
int day = int.Parse(s.Substring(6, 2));
int hour = int.Parse(s.Substring(8, 2));
int minute = int.Parse(s.Substring(10, 2));
DateTime dt = new DateTime(year, month, day, hour, minute, 0, DateTimeKind.Utc);
return dt;
}
输出是:
201212120600
201