用C#编写一个计算退休日期的Windows程序

一、算法思路

  程序设置人60周岁退休。退休时间为出生年份60年后出生月份的下一个月的1号。

  举例:

  李某2000.04月(无论哪天)出生,他的退休时间是2060年5月1日。

二、程序设计

  程序设计界面如下:

  

        界面构成:2个label、1个timePicker、1个textBox、1个按钮。

       计算按钮的事务处理过程代码:

 1         private void button1_Click(object sender, EventArgs e)
 2         {
 3             
 4             //算法思路1
 5             DateTime birthdayDate, birthdayDate_new;
 6             string year, month, day, endDate_new;
 7                    
 8             birthdayDate = Convert.ToDateTime(dateTimePicker1.Text);
 9             birthdayDate_new = birthdayDate.AddMonths(1);
10             year = birthdayDate.ToString("yyyy");
11 
12             year = (Convert.ToInt32(year) + 60).ToString();
13             month = birthdayDate_new.ToString("MM");
14             day = "01";
15 
16             endDate_new = year +""+month +""+ day+"";
17 
18             textBox1.Text = endDate_new;
19             
20             /*
21             //算法思路2
22             DateTime birthdayDate, endDate;
23             birthdayDate = Convert.ToDateTime(dateTimePicker1.Text);
24             endDate = birthdayDate;
25             float age;
26             float Month;
27             age = 0;
28             
29             while (age <= 60)
30             {
31                 endDate = endDate.AddDays(1);
32                 Month = (endDate.Year - birthdayDate.Year)*12+(endDate.Month-birthdayDate.Month);
33                 age = Month/12;
34             }
35             textBox1.Text = endDate.ToLongDateString();
36             */
37         }

执行效果:

本文结束。

 

    

posted @ 2022-06-02 09:39  美人她爹  阅读(115)  评论(0编辑  收藏  举报