C# 获取当前年月日

2024-12-24 18:44:39
推荐回答(4个)
回答1:

string t =DateTime.Now.ToString("yyyyMMdd");
这样就行!

回答2:

DateTime.Now.ToString("yyyyMMdd")

~
~
~
~
~
~
~
~

回答3:

string a = DateTime.Now.ToString("yyyyMMdd");

回答4:

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;