I. Use the ChineseLunisolarCalendar object to obtain the Chinese zodiac name from the year,
Ii. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. text; using System. windows. forms; namespace GetShengXiao {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private void btn_Get_Click (object sender, EventArgs e) {System. globalization. chineseLunisolarCalendar chinseCaleander = // create a Calendar Object (Chinese) LunisolarCalendar divides time into multiple parts, such as year, month, and day. Year is calculated based on the lunar calendar, while day and month are calculated based on the lunar calendar. New System. globalization. chineseLunisolarCalendar (); string TreeYear = "rat, ox, Tiger, Rabbit, dragon, Snake, horse, monkey, chicken, dog, and pig"; // create a string object int intYear = chinseCaleander. getSexagenaryYear (DateTime. now); // calculate the year information. GetSexagenaryYear calculates the year in the cycle (60 years) corresponding to the specified date. String Tree = TreeYear. substring (chinseCaleander. // obtain the Zodiac information GetTerrestrialBranch (intYear)-1, 1); // GetTerrestrialBranch calculates the geographic branch of the specified year in the (60 years) cycle, // Substring (x, y) retrieve the substring from this instance. The substring starts from the specified character position and has the specified length MessageBox. show ("this year is the Zodiac" + Tree + "year", // output the Zodiac information "judge the Zodiac", MessageBoxButtons. OK, MessageBoxIcon. information );}}}
3. now. tostring obtains the day of the week,
4. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace GetWeek {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private void btn_GetWeek_Click (object sender, EventArgs e) {MessageBox. show ("today is:" // display the week information + DateTime. now. toString ("dddd ")," Prompt! "); // Dddd is Sunday, ddd is day, dd is 01 }}}