string时间转换为时间格式

public string formatDataStr(string objstring)
        {
            if (objstring == "" || objstring == null || objstring == ".")
            {
                return "";
            }
            else
            {
                string tmpresultstr;
                objstring = objstring.Replace(",", ".").Replace(",", ".").Replace(" ", "").Replace("/", ".").Replace("-", ".");
                string[] objstringlist = objstring.Split('.');
                if (objstringlist.Count() >= 1)
                {
                    if (objstringlist[0].Trim().Length == 2)
                    {
                        tmpresultstr = "20" + objstringlist[0].Trim();
                    }
                    else
                    {
                        tmpresultstr = objstringlist[0].Trim();
                    }
                    for (int i = 1; i < objstringlist.Count(); i++)
                    {
                        if (objstringlist[i].Trim().Length == 1)
                        {
                            objstringlist[i] = "0" + objstringlist[i].Trim();
                        }
                        tmpresultstr = tmpresultstr + "." + objstringlist[i];
                    }
                    return tmpresultstr;
                }
                else
                {
                    return objstring;
                }
            }
        }

posted @ 2012-09-19 16:25  Uoolo  阅读(840)  评论(0编辑  收藏  举报