Can anybody tell me that how I can get current month and year and show it in a label in ASP.NET?
有谁能告诉我,我怎么才能得到现在的月份和年份,并在ASP.NET的标签中显示它?
5 个解决方案
#1
46
If you have following two labels:
如果你有以下两个标签:
<asp:Label ID="MonthLabel" runat="server" />
<asp:Label ID="YearLabel" runat="server" />
Than you can use following code just need to set the Text Property for these labels like:
您可以使用以下代码来设置这些标签的文本属性,比如:
MonthLabel.Text = DateTime.Now.Month.ToString();
YearLabel.Text = DateTime.Now.Year.ToString();
#2
25
Use the DateTime.Now property. This returns a DateTime object that contains a Year and Month property (both are integers).
使用DateTime。现在的财产。它返回一个DateTime对象,该对象包含一个年和一个月的属性(都是整数)。
string currentMonth = DateTime.Now.Month.ToString();
string currentYear = DateTime.Now.Year.ToString();
monthLabel.Text = currentMonth;
yearLabel.Text = currentYear;
#3
13
Like this:
是这样的:
DateTime.Now.ToString("MMMM yyyy")
For more information, see DateTime Format Strings.
有关更多信息,请参见DateTime格式字符串。
#4
2
label1.Text = DateTime.Now.Month.ToString();
and
和
label2.Text = DateTime.Now.Year.ToString();
#5
0
using System.Globalization;
LblMonth.Text = DateTime.Now.Month.ToString();
DateTimeFormatInfo dinfo = new DateTimeFormatInfo();
int month = Convert.ToInt16(LblMonth.Text);
LblMonth.Text = dinfo.GetMonthName(month);
#1
46
If you have following two labels:
如果你有以下两个标签:
<asp:Label ID="MonthLabel" runat="server" />
<asp:Label ID="YearLabel" runat="server" />
Than you can use following code just need to set the Text Property for these labels like:
您可以使用以下代码来设置这些标签的文本属性,比如:
MonthLabel.Text = DateTime.Now.Month.ToString();
YearLabel.Text = DateTime.Now.Year.ToString();
#2
25
Use the DateTime.Now property. This returns a DateTime object that contains a Year and Month property (both are integers).
使用DateTime。现在的财产。它返回一个DateTime对象,该对象包含一个年和一个月的属性(都是整数)。
string currentMonth = DateTime.Now.Month.ToString();
string currentYear = DateTime.Now.Year.ToString();
monthLabel.Text = currentMonth;
yearLabel.Text = currentYear;
#3
13
Like this:
是这样的:
DateTime.Now.ToString("MMMM yyyy")
For more information, see DateTime Format Strings.
有关更多信息,请参见DateTime格式字符串。
#4
2
label1.Text = DateTime.Now.Month.ToString();
and
和
label2.Text = DateTime.Now.Year.ToString();
#5
0
using System.Globalization;
LblMonth.Text = DateTime.Now.Month.ToString();
DateTimeFormatInfo dinfo = new DateTimeFormatInfo();
int month = Convert.ToInt16(LblMonth.Text);
LblMonth.Text = dinfo.GetMonthName(month);