在DOB中增加60年 [英] Adding 60 years in DOB
问题描述
嗨
在我的Windows窗体应用程序中有两列,即:我使用三个组合框作为dd(comboBox9),mm(comboBox10),yyyy(comboBox11)和退休日期(textBox3)的DOB。用户输入的DOB应通过向他/她的DOB添加60年自动显示用户的退休日期。我已为此操作编写了一些代码,因为
Hi
In my Windows Form Application there is two columns viz; DOB for which I used three comboBoxes as "dd(comboBox9),mm(comboBox10),yyyy(comboBox11)" and Date of Retirement(textBox3). The DOB entered by the user should automatically show the user''s Date of Retirement by adding 60 years to his/her DOB. I have writtem some codes for this operation as
private void comboBox11_SelectedIndexChanged(object sender, EventArgs e)
{
DateTime dt = new DateTime();
//dt = ;
comboBox9.Text = dt.Day.ToString();
comboBox10.Text = dt.Month.ToString();
comboBox11.Text = dt.Year.ToString();
dt.AddYears(60);
textBox3.Text = dt.ToString();
}
输入DOB,显示日期为01-Jan-01 12:00:00 AM每个DOB的退休列,并将DOB列更改为1 1 2000.我无法找到合适的理由。请有人帮助我。
By entering the DOB, it shows 01-Jan-01 12:00:00 AM in the Date of Retirement column for every DOB and also changes the DOB column to 1 1 2000. I am unable to find out suitable reason. Please someone help me.
推荐答案
请检查一下。
Please check this.
DateTime dt = new DateTime(Convert.ToInt32(comboBox11.Text), Convert.ToInt32(comboBox10.Text), Convert.ToInt32(comboBox9.Text));
DateTime dt1 = dt.AddYears(60);
textBox3.Text = dt1.ToShortDateString();
原因是你在datetime上做了一个新的并且从不使用所选的用户日期。你只是使用默认日期。
所以请尝试这样做。
The reason for that is you are doing a new on datetime and never using the user selected date. You are just using the default date.
so try doing this instead.
DateTime dt = new DateTime(Convert.ToInt32(comboBox11.Text), Convert.ToInt32(comboBox10.Text), Convert.ToInt32(comboBox9.Text));
dt.AddYears(60);
textBox3.Text = dt.ToString();
这应解决问题。
This should fix the problem.
这篇关于在DOB中增加60年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!