如何计算android开发中的年龄 [英] How to calculate age in android development

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

问题描述

大家好,



我想在选择日期选择器时计算一个人的年龄




我是一个自学的机器人开发银行家并且没有编程知识。请帮助我解决最简单的问题。



我尝试过:



谷歌搜索并尝试使用许多代码并最终让自己感到困惑。

Hi Everyone,

I want to Calculate age of a person, as soon as he selects the datepicker


I'm a self learning android developing Banker and don't have a programming knowledge. Kindly help me out in a easiest solution.

What I have tried:

Googled and tried to use many codes and ended up confusing myself.

推荐答案

这并不困难。您的输入是当前日期(例如现在)和用户出生日期(例如 bd )。

用户年龄(用户年龄)(伪代码)

It is not difficult. Your inputs are current date (say now) and the user date of birth (say bd).
The user age (how many years the user old) is (pseudocode)
age = now.year - bd.year;

if (now.day_of_year < bd.day_of_year)
  age = age - 1;


你会怎么用铅笔和纸做的?直到你走得那么远,弄乱代码是没有实际意义的。
How would you do it with pencil and paper? Until you get that far, messing with code is a moot point.


引用:

用Google搜索并尝试使用许多代码,最终让自己感到困惑。

Googled and tried to use many codes and ended up confusing myself.

给初学者的建议,不要试图通过搜索随机代码来学习。

你需要找一些教程并按照它们来学习。

学习编程没有神奇的简单方法。

建议:在学习教程的同时暂停项目。

Advice to beginner, don't try to learn by searching 'random' code.
You need to find some tutorials and follow them to learn something.
There is no magic easy way to learn programming.
Advice: Put your project on hold while you follow the tutorials.


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

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