string t =DateTime.Now.ToString("yyyyMMdd");
这样就行!
DateTime.Now.ToString("yyyyMMdd")
~
~
~
~
~
~
~
~
string a = DateTime.Now.ToString("yyyyMMdd");
Datetime.nowtime.tostring("yyyyMMdd")
这里可能出现201271的情况,可以用下面的方法:
string NowYear=Datetime.nowtime.tostring("yyyy");
string NowMouth=Datetime.nowtime.tostring("MM");
string NowDay=Datetime.nowtime.tostring("dd");
if (NowMouth.lenght==1)
{
NowMouth="0"+NowMouth;
}
if (NowDay.lenght==1)
{
NowDay="0"+NowDay;
}
string NowTime=NowYear+NowMouth+ NowDay;