Bom Dia Pessoal,
Estou fazendo um App e gostaria de retornar a diferença entre uma data que eu tenho salva no banco no formato string com a data atual.
Apenas
estou calculando a diferença de anos para ver se da certo depois faria
completo, fiz algumas coisas mas a idade fica mostrando somente 0.
Se alguem puder me passar alguma dica, muito obrigado!
package br.com.marcosoliveira.cadastroclientenovo;
import android.widget.Toast;
import java.security.PublicKey;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
-
Created by marcos on 09/04/16. */ public class Cliente { private int id; private String nome; private String telefone; private String cpf; private String dtNascimento; private String genero; private int idade;
public Cliente (){}
public Cliente (int id, String nome, String telefone, String cpf, String dtNascimento, String genero, int idade){ <a href="http://this.id">this.id</a> = id; this.nome = nome; this.telefone = telefone; this.cpf = cpf; this.dtNascimento = dtNascimento; this.genero = genero; this.idade = idade;
} public int getId(){ return id; } public void setId(int id){ <a href="http://this.id">this.id</a> = id; } public String getNome(){ return nome; } public void setNome(String nome){ this.nome = nome; } public String getTelefone(){ return telefone; } public void setTelefone(String telefone){ this.telefone = telefone; } public String getCpf(){ return cpf; } public void setCpf(String cpf){ this.cpf = cpf; } public String getDtNascimento(){ return dtNascimento; } public void setDtNascimento(String dtNascimento){
this.dtNascimento = dtNascimento;
} public String getGenero(){ return genero; } public void setGenero (String genero){
this.genero = genero;
}
public int calcularIdade(){
String[] arrayData = getDtNascimento().split("/"); int dia = Integer.valueOf(arrayData[0]); int mes = Integer.valueOf(arrayData[1]); int ano = Integer.valueOf(arrayData[2]); Calendar c = Calendar.getInstance(); int anoA = c.get(Calendar.YEAR); int mesA = c.get(Calendar.MONTH)+1; int diaA = c.get(Calendar.DAY_OF_MONTH); int calcDias = diaA - dia; int calcMes = mesA - mes; int calAnos = anoA - ano; idade = anoA; return idade;}
@Override
public String toString () {return " NOME: " + nome + ". Nascimento: " + idade +".";
}
}