想把日期格式"dd\MM\yyyy"用正则表达式替换成"yyyy\MM\dd",如"19\03\2012"

解决方案 »

  1.   

    不用替换
    DateTimestr.ToString("yyyy\MM\dd")
      

  2.   

    string dr = DateTime.Now.ToString(@"yyyy\\MM\\dd");
      

  3.   

    参考
    http://www.csharpwin.com/csharpspace/9442r8768.shtml
      

  4.   

    str=Regex.Replace(str,@"(\d{2})\\(\d{2})\\(\d{4})","$3\\$2\\$1");
      

  5.   


                string source = @"(aa19\03\2012bb";
                Regex reg = new Regex(@"(?<day>[\d]{2})\\(?<month>[\d]{2})\\(?<year>[\d]{4})");
                source = reg.Replace(source, "${year}\\${month}\\${day}");