ASP.NET(C#) 开发WebForm小弟使用如下代码的时候
Label1.Text = DateTime.Now.ToShortDate();如果日期为2005年7月1日,那么这样将取得2005-7-1的日期格式,现在想要2005-07-01的日期格式,代码要如何写啊???最好是简单一点的方法!!请大侠指点一下,谢谢!
学习,关注……

解决方案 »

  1.   

    length判断下位数不就可以了?
      

  2.   

    如果需要特别的日期格式可以自己写
    Label1.Text = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString("00") + "-" + DateTime.Now.Day.ToString("00");
      

  3.   

    txt_time.Text = Convert.ToDataTime(strTime).ToShortTimeString();请问为什么还会txt_time.Text的值是2005-5-5 00:00:00这样出现?
    在数据表时间字段的数据是:2005-5-5
      

  4.   

    数据库中读出的数据是精确到秒的.可以以下的方式获得没有具体时间的日期
    select Varchar(varchar(30),birthday,111) as birthday from customer
    这样就可以啦.
      

  5.   

    DateTime.Now.Tostring("yy年MM月dd日");
      

  6.   

    应该是:DateTime.Now.Tostring("yyyy年MM月dd日");