how to get current month and year

前端 未结 8 636
南方客
南方客 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 09:52

    Use the DateTime.Now property. This returns a DateTime object that contains a Year and Month property (both are integers).

    string currentMonth = DateTime.Now.Month.ToString();
    string currentYear = DateTime.Now.Year.ToString();
    
    monthLabel.Text = currentMonth;
    yearLabel.Text = currentYear;
    

提交回复
热议问题