2010-10-08 14 views

उत्तर

23

डेटटाइम.अब संपत्ति का उपयोग करें। यह डेटटाइम ऑब्जेक्ट देता है जिसमें एक वर्ष और महीना संपत्ति होती है (दोनों पूर्णांक होते हैं)।

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

monthLabel.Text = currentMonth; 
yearLabel.Text = currentYear; 
13
इस तरह

:

DateTime.Now.ToString("MMMM yyyy") 

अधिक जानकारी के लिए DateTime Format Strings देखते हैं।

+0

इनलाइन कोड के साथ प्रयुक्त अच्छा और आसान है। <% = दिनांक समय.अब.ToString ("MMMM yyyy")%> – atjoedonahue

2
label1.Text = DateTime.Now.Month.ToString(); 

और

label2.Text = DateTime.Now.Year.ToString(); 
43

आपको दो लेबल निम्नलिखित है:

<asp:Label ID="MonthLabel" runat="server" /> 
<asp:Label ID="YearLabel" runat="server" /> 

जैसे इन लेबलों के लिए पाठ संपत्ति निर्धारित करने की आवश्यकता से आप निम्नलिखित कोड का उपयोग कर सकते हैं:

MonthLabel.Text = DateTime.Now.Month.ToString(); 
YearLabel.Text = DateTime.Now.Year.ToString(); 
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); 
संबंधित मुद्दे