本帖最后由 gantanhao00 于 2009-10-08 09:59:04 编辑

解决方案 »

  1.   

    string str = System.DateTime.Now.ToString("yyyy-M-d h:mm:ss");
      

  2.   

    string regex = @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"; //日期部分
      regex += @"(\s(((0?[0-9])|(2[0-3])|(1[0-9]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"; //时间部分
      

  3.   


    ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]((((0?[13578])|(1[02]))[\-\/\s]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|(2[0-3])|(1[0-9]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$
    参考一下吧楼主 http://www.cnblogs.com/a409254613/archive/2008/05/06/1185273.html
      

  4.   

    using System;
    using System.Text.RegularExpressions;class Test
    {
      static void Main()
      {
        string strAll = @"t0=new Date().getTime();
    nyear=2009;
    nmonth=10;
    nday=8;
    nwday=5-1;
    nhrs=9;
    nmin=57;
    nsec=23;
    s=document.URL;pos=s.indexOf(""#"");
    fstyle=decodeURI(s.substring(pos+1,s.length));";    string year   = Regex.Match(strAll, @"(?i)(?<=\bnyear\s*=\s*)\d+" ).Value;
        string month  = Regex.Match(strAll, @"(?i)(?<=\bnmonth\s*=\s*)\d+").Value;
        string day    = Regex.Match(strAll, @"(?i)(?<=\bnday\s*=\s*)\d+"  ).Value;
        string hour   = Regex.Match(strAll, @"(?i)(?<=\bnhrs\s*=\s*)\d+"  ).Value;
        string minute = Regex.Match(strAll, @"(?i)(?<=\bnmin\s*=\s*)\d+"  ).Value;
        string second = Regex.Match(strAll, @"(?i)(?<=\bnsec\s*=\s*)\d+"  ).Value;    //.要求str结果为:2009-10-8 9:57:23
        string str = string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, day, hour, minute, second);
        Console.WriteLine(str);
      }
    }
      

  5.   

    using System;
    using System.Text.RegularExpressions;class Test
    {
      static void Main()
      {
        string strAll = @"t0=new Date().getTime();
    nyear=2009;
    nmonth=10;
    nday=8;
    nwday=5-1;
    nhrs=9;
    nmin=57;
    nsec=23;
    s=document.URL;pos=s.indexOf(""#"");
    fstyle=decodeURI(s.substring(pos+1,s.length));";    Regex r = new Regex(@"(?si).*?\bnyear\s*=\s*(\d+).*?\bnmonth\s*=\s*(\d+).*?\bnday\s*=\s*(\d+).*?\bnhrs\s*=\s*(\d+).*?\bnmin\s*=\s*(\d+).*?\bnsec\s*=\s*(\d+).*");    //.要求str结果为:2009-10-8 9:57:23
        string str = r.Replace(strAll, "$1-$2-$3 $4:$5:$6");
        Console.WriteLine(str);
      }
    }