我需要在我的txtbox中显示年份的年龄

编程入门 行业动态 更新时间:2024-10-26 08:30:53
本文介绍了我需要在我的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中显示年份的年龄

本文发布于:2023-11-27 08:48:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:年份   年龄   txtbox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!