我需要在我的txtbox中显示年份的年龄 [英] I need to display age in year in my txtbox
本文介绍了我需要在我的txtbox中显示年份的年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个问题我需要年龄在几年(int)
这是我的一段代码
我尝试了什么:
Hi
I have a problem I need the age to be in Years(int)
Here is my piece of code
What I have tried:
Hi
See this is my piece of code ,and all I need is to get a AGE in TxtAge.txt texbox like 50 ,51.How can I achieve this any pulgin needed?
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
txtDob.Text = Calendar1.SelectedDate.ToString();
Calendar1.Visible = false;
DateTime txtMyDate = DateTime.ParseExact(txtAge.Text, "M/d/yyyy", CultureInfo.InvariantCulture);
}
推荐答案
如果你想计算年龄,请尝试改编自这个:
If you want to calculate age in years, try and adapt from this:
using System;
public class Program
{
public static void Main()
{
DateTime dob = new DateTime(2000, 1, 11); // Calendar1.SelectedDate
DateTime today = DateTime.Today;
int age = today.Year - dob.Year;
Console.WriteLine("Age in years " + age);
}
}
学习日期时间结构(系统) [ ^ ]
要在文本框中显示日历和计算年龄,完整代码如下,请检查出来:
使用系统;
命名空间CalenderConcepts
{
public partial class Calender:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
}
protected void Calendar1_SelectionChanged(object sender,EventArgs e)
{
txtDBO.Text = Calendar1.SelectedDate.ToString();
Calendar1.Visible = false;
int year = DateTime。 Now.Ye ar - Calendar1.SelectedDate.Year;
int months = DateTime.Now.Month - Calendar1.SelectedDate.Month;
string ageval =(year +years+ months +月);
TextBox1.Text = ageval;
Calendar1.Visible = true;
}
}
}
谢谢,
Abhishek
To Display Calender and Calcualte the Age in a Text box , The Fully Code is below, Please Check it Out:
using System;
namespace CalenderConcepts
{
public partial class Calender : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
txtDBO.Text = Calendar1.SelectedDate.ToString();
Calendar1.Visible = false;
int year = DateTime.Now.Year - Calendar1.SelectedDate.Year;
int months = DateTime.Now.Month - Calendar1.SelectedDate.Month;
string ageval = (year + "years" + months + "months");
TextBox1.Text = ageval;
Calendar1.Visible = true;
}
}
}
Thanks,
Abhishek
这篇关于我需要在我的txtbox中显示年份的年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文