Example
The code is as follows |
Copy Code |
Lbday.text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName (DateTime.Now.DayOfWeek); |
Example 1
The code is as follows |
Copy Code |
string[] Day = new string[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String week = Day[convert.toint32 (DateTime.Now.DayOfWeek.ToString ("D"))]. ToString (); Lbday.text = week; |
Example 2
Output week by number ordinal
The code is as follows |
Copy Code |
Select.cs program content: Through the input digital 0~6, the output week each day English words to demonstrate if statement and switch statement usage Using System; Class Select { public static void Main () { Console.WriteLine ("Please enter a number:"); Console.WriteLine ("1~6 says Monday to Saturday; 0 means Sunday"); string s = Console.ReadLine (); int n = Int. Parse (s); if (n<0 | | n>6)//Judge input time legal { Console.WriteLine ("Input Error"); Error handling } else//input is correct, processed according to the selection { Switch (n) { Case 1://input as 1 o'clock processing Console.WriteLine ("Monday is Monday"); Break After processing, jump out of switch Case 2: Console.WriteLine ("Tuesday is Tuesday"); Break Case 3: Console.WriteLine ("Wednesday is Wednesday"); Break Case 4: Console.WriteLine ("Thursday is Thursday"); Break Case 5: Console.WriteLine ("Friday is Friday"); Break Case 6: Console.WriteLine ("Saturday is Saturday"); Break Case 0: Console.WriteLine ("Sunday is Sunday"); Break Default://In fact, before the input has been processed, the following statement cannot be reached Console.WriteLine ("It is a crazy day!"); In this example, the default usage, Break The reader can try to remove the IF statement and enter an illegal result. } } } } |
Example 3
Calculate the day of the week according to the month
The code is as follows |
Copy Code |
//y-year, M-month, D-Date string caculateweekday (int y,int m, int d) { if (m==1) m=13; if (m==2) m=14 ; int week= (d+2*m+3* (m+1)/5+y+y/4-y/100+y/400)%7; String weekstr= ""; Switch (week) { case 1:weekstr= ' Monday '; break; & nbsp Case 2:weekstr= "Tuesday"; Break case 3:weekstr= "Wednesday"; case 4:weekstr= "Thursday"; case 5:weekstr= "Friday"; case 6:weekstr= "Saturday"; case 7:weekstr= "Sunday"; } return weekstr; } Use method Label1.text=caculateweekday (2004,12,9); |