计算一个人的年龄 [英] calculate age of a person

查看:71
本文介绍了计算一个人的年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在窗口应用程序中的c#中计算一个人的年龄?

How to calculate age of a person in c# in window application ?

推荐答案

获取用户输入的出生日期.
将此存储在datetime 对象中.
从系统或网络获取当前日期.
将此存储在datetime 对象中.

datetime.year/month/day上使用简单的算术计算年龄.

使用日历控件确保用户输入的日期格式正确.
take the user input for date of birth.
store this in datetime object.
get the current date from the system or from network.
store this in datetime object.

use simple arithmetic on datetime.year/month/day to calculate the age.

use calender control to make sure user entered date is in correct format.


请参阅以下内容:

http://snippets.dzone.com/posts/show/1632 [ http://stackoverflow.com/questions/9/how-do- i-calculate-someones-age-in-c [ ^ ]
Refer these:

http://snippets.dzone.com/posts/show/1632[^]

http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c[^]


一种方法是使用DateTime类 ^ ]可能会有用.
One way would be to use the DateTime class this[^] might be useful.


这篇关于计算一个人的年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆