根据字符串截取周的信息转换为这周的最后一天
String tempSN ="A201303001";
怎么根据这个字符串截取03,知道是一年的第3周
让后转换成这周的最后一天
转换完的效果是2013-01-20
string
------解决方案-------------------- String tempSN = "A201303001";
int year = int.Parse(tempSN.Substring(1, 4));
int week = int.Parse(tempSN.Substring(5, 2));
DateTime dt = new DateTime(year, 1, 1);
dt = dt.AddDays(7 * (week - 1));
while (dt.DayOfWeek != DayOfWeek.Sunday)
dt = dt.AddDays(1);
Response.Write(dt.ToString());
------解决方案-------------------- String tempSN = "A201303001";
int year = Convert.ToInt32(tempSN.Substring(1, 4));
int week = Convert.ToInt32(tempSN.Substring(5, 2));
DateTime firstDay = new DateTime(year, 1, 1);
DateTime result = firstDay.AddDays(7 - Convert.ToInt32(firstDay.DayOfWeek) + (week - 1) * 7);
Console.WriteLine(result);