string aa=DateTime.Now.ToShortDateString();

string aa = "2004-03-31 15:11:36";
string bb = aa.SubString(0,9);

解决方案 »

  1.   

    将此实例的值转换为其等效的短日期字符串表示形式。[Visual Basic]
    Public Function ToShortDateString() As String[C#]
    public string ToShortDateString();[C++]
    public: String* ToShortDateString();[JScript]
    public function ToShortDateString() : String;返回值
    一个字符串,它包含与此实例的日期值等效的数字月份、该月中的数字日期和年份。备注
    此实例的值使用短日期格式字符“d”进行格式化。返回值与 ToString ("d", null) 返回的值相同。有关格式字符、格式模式及它们产生的输出的更多信息,请参见格式化概述主题。有关更改与格式字符相关的格式模式的更多信息,请参见 DateTimeFormatInfo 类。此方法使用从当前区域性导出的格式信息。有关当前区域性的更多信息,请参见 CurrentCulture 类。可使用 CultureInfo.DateTimeFormat 属性获取当前区域性的 DateTimeFormatInfo。
      

  2.   

    DateTime dd=DateTime.Now;
    string ss=dd.ToString("yyyy-MM-dd");上面代码可以得到2004-03-31格式时间。