datetime - how to get number of years between two dates in android -
this question has answer here:
- how calculate someone's age in java? 26 answers
hello creating android app in have 2 string of different dates want number of years between these dates please me how can this? here code
string birthday=p.getstring("birthday"); log.i("bd", string.valueof(birthday)); calendar c = calendar.getinstance(); simpledateformat df = new simpledateformat("dd mmm, yyyy"); final string formatteddate = df.format(c.gettime()); log.i("formatteddate", string.valueof(formatteddate));
where birthday saved date , formatteddate current date want difference between these
please try code
string birthday = p.getstring("birthday"); calendar calendarbirthday = calendar.getinstance(); simpledateformat sdf = new simpledateformat("dd mmm, yyyy"); calendarbirthday.settime(sdf.parse(birthday)); calendar calendarnow = calendar.getinstance(); int yearnow = calendarnow.get(calendar.year); int yearbirthday = calendarbirthday.get(calendar.year); int years = yearnow - yearbirthday;
Comments
Post a Comment