how to get current month and year

前端 未结 8 638
南方客
南方客 2020-12-25 09:39

Can anybody tell me that how I can get current month and year and show it in a label in ASP.NET?

相关标签:
8条回答
  • 2020-12-25 10:12
    using System.Globalization;
    
    LblMonth.Text = DateTime.Now.Month.ToString();
    
    DateTimeFormatInfo dinfo = new DateTimeFormatInfo();
    int month = Convert.ToInt16(LblMonth.Text);
    
    LblMonth.Text = dinfo.GetMonthName(month);
    
    0 讨论(0)
  • 2020-12-25 10:15

    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();
    
    0 讨论(0)
提交回复
热议问题