现在有2种时间字符串
10/11/2009 10月11号 
10/11/2009 11月10号问题是,能不能不做字符串的操作,
有函数直接能返回 DateTime类型 格式为 yyyy-MM-dd 的
具体该怎么写

解决方案 »

  1.   

    select convert(varchar(10),getdate(),120)
    ----------
    2009-06-16(1 行受影响)
      

  2.   

                String str = "10/11/2009";
                DateTime dt = Convert.ToDateTime(str);
                dateTimePicker1.Value = dt;
      

  3.   

    参考:            string str = "10/11/2009";
                DateTime dt = DateTime.ParseExact(str, "MM/dd/yyyy", new System.Globalization.CultureInfo("en-us"));
                Console.WriteLine(dt.ToString("yyyy-MM-dd"));
                dt = DateTime.ParseExact(str, "dd/MM/yyyy", new System.Globalization.CultureInfo("fr-fr"));
                Console.WriteLine(dt.ToString("yyyy-MM-dd"));/*
    输出:
    2009-10-11
    2009-11-10
    */
      

  4.   

    现将字符串转化为时间
    DateTime temp = Convert.ToDateTime(string);
    temp.ToString("yyyy-MM-dd");
    temp.ToString("yyyy-dd-MM");
      

  5.   

     DateTime _Time1 = DateTime.ParseExact("10/11/2009", "MM'/'dd'/'yyyy", Application.CurrentCulture);            DateTime _Time2 = DateTime.ParseExact("10月11号", "MM'月'dd'号'", Application.CurrentCulture);
      

  6.   


    //用正则的一种方法。
                String strInput = @"10/11/2009";
                Regex objRegex = new Regex(@"^(\d{1,2})\/(\d{1,2})\/(\d{4})$");
                String strResult1 = objRegex.Replace(strInput, "$3年$1月$2日");//2009年10月11日
                String strResult2 = objRegex.Replace(strInput, "$3年$2月$1日");//2009年11月10日
      

  7.   

    问的就是这个参数了 new System.Globalization.CultureInfo("en-us")  3Q