如何把这样的时间格式:20130523123214000+0800转换成:2013-05-23 12:32:14.000?不许用subString()拼接

解决方案 »

  1.   


                string str = @"20130523123214000+0800";
                string strmatch = @"([\d]{4})([\d][\d])([\d][\d])([\d][\d])([\d][\d])([\d][\d])";
                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
                System.Text.RegularExpressions.Match m = reg.Match(str);
                string datestr = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value+" "
                    +m.Groups[4].Value+":"+m.Groups[5].Value+":"+m.Groups[6].Value;
                MessageBox.Show(datestr);
      

  2.   

    楼上的加上这个那就是更完美了,试试看精确到毫秒的:
            void a()
            {
                string str = @"20130523123214125+0800";
                string strmatch = @"([\d]{4})([\d][\d])([\d][\d])([\d][\d])([\d][\d])([\d][\d])([0-9]{3})";
                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
                System.Text.RegularExpressions.Match m = reg.Match(str);
                string datestr = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value + " " + m.Groups[4].Value + ":" + m.Groups[5].Value + ":" + m.Groups[6].Value+"."+m.Groups[7].Value;
                MessageBox.Show(datestr);
            }