不管输入的是 01-Jan-2008,01-01-2008, 01-jan-2008 or 01-JAN-2008 哪种,
保存到数据库里面都要是01-Jan-2008 这种..  这要怎么转哦? 

解决方案 »

  1.   

    恩,这个好办,
    string Month = **;//输入的日期的月
    if(Month=="01"||Month=="jan"||Month=="JAN")
    {
        Month = "Jan";
    }
    这样就OK了。
      

  2.   

    try:            Console.WriteLine(DateTime.Parse("01-Jan-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
                Console.WriteLine(DateTime.Parse("01-01-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
                Console.WriteLine(DateTime.Parse("01-jan-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
                Console.WriteLine(DateTime.Parse("01-JAN-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
    /*
    输出:
    01-Jan-2008
    01-Jan-2008
    01-Jan-2008
    01-Jan-2008
    */
      

  3.   

    try thisstring[] dates = { "01-Jan-2008", "01-01-2008", "01-jan-2008", "01-JAN-2008" };
    DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
    foreach (string date in dates)
    {
         DateTime dt = DateTime.Parse(date);
         Console.WriteLine(dt.ToString("dd-MMM-yy", dtfi));
    }
      

  4.   

    string[] dates = { "01-Jan-2008", "01-01-2008", "01-jan-2008", "01-JAN-2008" };
    DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
    foreach (string date in dates)
    {
         DateTime dt = DateTime.Parse(date);
         Console.WriteLine(dt.ToString("dd-MMM-yyyy", dtfi));
    }
      

  5.   

       System.Globalization.DateTimeFormatInfo _DataTimeInfo = new System.Globalization.DateTimeFormatInfo();
                System.Globalization.CultureInfo _Info = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name);
                _Info.DateTimeFormat = _DataTimeInfo;
                System.Threading.Thread.CurrentThread.CurrentCulture = _Info;
                         string[] _Value = "01-Jan-2008,01-01-2008, 01-jan-2008, 01-JAN-2008".Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);           DateTime[] _Time = new DateTime[_Value.Length];
               for (int i = 0; i != _Time.Length; i++)
               {
                   string [] A =_Time[i].GetDateTimeFormats();
                   _Time[i] = Convert.ToDateTime(_Value[i]);
                   MessageBox.Show(_Time[i].ToString("dd-MMM-yyyy"));
               }
      

  6.   

    当我输入02-01-2000,出来的结果是 01-Feb-2000 
      

  7.   


                Response.Write(DateTime.Parse("01-Jan-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us"))+"<br />");
                Response.Write(DateTime.Parse("01-01-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")) + "<br />");
                Response.Write(DateTime.Parse("01-JAN-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")) + "<br />");
                Response.Write(DateTime.Parse("01-jan-2008").ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")) + "<br />");
      

  8.   


    DateTime dt = DateTime.ParseExact("02-01-2000", "dd-mm-yyyy", null);
    System.Globalization.DateTimeFormatInfo dtfi = System.Globalization.DateTimeFormatInfo.InvariantInfo;
    Console.WriteLine(dt.ToString("dd-MMM-yy", dtfi));
      

  9.   

    try:            Console.WriteLine(DateTime.ParseExact("02-01-2008", "d-M-yyyy", null).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
      

  10.   


    DateTime dt = DateTime.ParseExact("02-01-2000", "dd-mm-yyyy", null);
    System.Globalization.DateTimeFormatInfo dtfi = System.Globalization.DateTimeFormatInfo.InvariantInfo;
    Console.WriteLine(dt.ToString("dd-MMM-yy", dtfi));
      

  11.   


      Console.WriteLine(DateTime.ParseExact("02-01-2008", "d-M-yyyy", null).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));输入02-JAN-2000,这个报错..
      

  12.   


    输入02-JAN-2000,这个报错..
      

  13.   

    这次应该没问题了:            Console.WriteLine(DateTime.Parse("01-Jan-2008", new System.Globalization.CultureInfo("de-de")).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
                Console.WriteLine(DateTime.Parse("02-01-2008",new System.Globalization.CultureInfo("de-de")).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
                Console.WriteLine(DateTime.Parse("01-jan-2008", new System.Globalization.CultureInfo("de-de")).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));
                Console.WriteLine(DateTime.Parse("01-JAN-2008", new System.Globalization.CultureInfo("de-de")).ToString("dd-MMM-yyyy", new System.Globalization.CultureInfo("en-us")));