你把时间先读出来
然后用substring分割
然后重新组装

解决方案 »

  1.   

    public static string GetPadDateTime(System.DateTime D)
    {

    string temp=D.Year.ToString()+"-";
    if (D.Month<10)
    {
    temp+="0"+D.Month.ToString();
    }
    else
    {
    temp+=D.Month.ToString();
    }
    temp+="-";
    if (D.Day<10)
    {
    temp+="0"+D.Day.ToString();
    }
    else
    {
    temp+=D.Day.ToString();
    }
    return temp; }
    public static string GetPadDateTime(string D)
    {
    return GetPadDateTime(System.DateTime.Parse(D));
    }D 是传入的短时间格式日期或字符串
      

  2.   

    先谢谢两位,但我题目的意思是“假如操作系统原来的短日期格式是yy-m-d,我可以通过  控制面板->区域选项->日期->短日期->短日期格式  的方法把短日期格式设置为yyyy-MM-dd”,现在我需要通过C#代码来实现我刚才手工操作的过程。
      

  3.   

    你想做了windows?
    PFPF
    关注一下先
      

  4.   

    本人覺得改os的日期格式並不太好, 最好是將所寫的application system的日期格式設為你所需要的 'yyyy-MM-dd'.
      

  5.   

    System.Datetime.Parse(strDateTime).ToShortDateString();
      

  6.   

    DateTime.Now.ToString("yyyy-MM-dd");
    -----------------
    可以的,我也这么用过
      

  7.   

    来晚了,,DateTime.Now.ToString("yyyy-MM-dd");
      

  8.   

    DateTime.Now.ToString("yyyy-mm-dd");
    没错的,放心用吧!