1
I am doing the insertion of a DATE type value in my project, for that I had to convert it, in my corresponding class, my Dt_reading tribute, is declared as string and in the database it is as Date. For this, the moment I am entering the register in the bank, I am converting it, as below:
public Consumo inserir (Consumo consumo){
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.applyPattern("yyyy-MM-dd");
Date data = (Date) dateFormat.parse(consumo.dt_leitura.getText());
ContentValues valores = new ContentValues();
valores.put("dt_leitura",dateFormat.format(data));
valores.put("registro", consumo.getRegistro());
consumo.setId(db.insert("consumo", null, valores ));
return consumo;
}
Only on the stretch
Date data = (Date) dateFormat.parse(consumo.dt_leitura.getText());
is returning the following error:
The method gettext() is Undefined for the type String
Could you tell me if I am also making the correct date conversion?
Hello extension, Thanks for the attention and reply Unfortunately after I changed the way you showed me Date data = (Date) dateFormat.parse(consumption.dt_reading); still returns me the error Unhandled Exception type Parseexception, would know tell me the reason why ?
– Geovani Rafael Sório
Without knowing what
consumo.dt_leitura
returns/contains no.– ramaral
Amaral, it worked out the way it did, actually this mistake I mentioned above, the application was only informed that it needed a Try catch, put and worked. thank you
– Geovani Rafael Sório