datetime - how to get number of years between two dates in android -


this question has answer here:

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

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

delphi - Indy UDP Read Contents of Adata -