string类型组成DateTime类型 如题 .. 例:我要把 091217 100226 转成 09-12-17 10:02:26 困扰好久 ...希望大家帮我下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Convert.ToDateTime("091217 100223").ToString("yyyy-MM-dd HH:mm:ss") DateTime dat = DateTime.Parse(s);s是个时间字符串 static DateTime StrToDateTime(string str) { Regex re=new Regex(@"\d{2}"); MatchCollection mc = re.Matches(str); List<int> list = new List<int>(); foreach (Match m in mc) list.Add(Convert.ToInt32(m.Value)); return new DateTime(list[0], list[1], list[2], list[3], list[4], list[5]); } DateTime dt = StrToDateTime("091217 100226 "); Console.WriteLine(dt.ToString("yy-MM-dd hh-mm-ss")); DateTime dat = new DateTime(); string h = "09-12-17 10:02:26"; dat = DateTime.Parse(h); string strDate = "091217 100223"; strDate = strDate.Replace(" ",""); strDate = strDate.Trim().Substring(0, 2) + "-" + strDate.Trim().Substring(2, 2) + "-" + strDate.Trim().Substring(4, 2) + " " + strDate.Trim().Substring(6, 2) + ":" + strDate.Trim().Substring(8, 2) + ":" + strDate.Trim().Substring(10, 2); DateTime dat = DateTime.Parse(s);s是个时间字符串全部是错的 Visual Studio里debugger一下,多试几次就有了 C# + Win7(Win2008)openFileDialog对话框的“尝试读取或写入受保护的内存”错误 T-SQL怎么写代码查询本年的一月一日? socket远程主机强迫关闭一个现有连接 C#怎么定义api的GetNextWindow? C#程序发布问题。 [原创]论现有计算机软件技术发展之我见 帮忙看看这个链接字符串 怎样在局域网中下载须要用户名和密码访问的文件! 在vb.net里面我这样做,可是在C#里面我不知道怎么做了?请进! StreamWriter乱码问题 excel 导入sql server c#如何向webbrowser控件发送命令
{
Regex re=new Regex(@"\d{2}");
MatchCollection mc = re.Matches(str);
List<int> list = new List<int>();
foreach (Match m in mc)
list.Add(Convert.ToInt32(m.Value));
return new DateTime(list[0], list[1], list[2], list[3], list[4], list[5]);
} DateTime dt = StrToDateTime("091217 100226 ");
Console.WriteLine(dt.ToString("yy-MM-dd hh-mm-ss"));
string h = "09-12-17 10:02:26";
dat = DateTime.Parse(h);
strDate = strDate.Replace(" ","");
strDate = strDate.Trim().Substring(0, 2) + "-" + strDate.Trim().Substring(2, 2) + "-" + strDate.Trim().Substring(4, 2)
+ " " + strDate.Trim().Substring(6, 2) + ":" + strDate.Trim().Substring(8, 2) + ":" + strDate.Trim().Substring(10, 2);
全部是错的