I'm doing the insertion of a DATE type value in my project, so I had to convert it, in my corresponding class, my tribute Dt_read, it is declared as string and in the database it is as Date. For this, at the moment I'm inserting the record in the database, I'm 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 in the stretch
Date data = (Date) dateFormat.parse(consumo.dt_leitura.getText());
You are returning the following error:
The method getText () is undefined for the type String
Could you tell me if I'm also doing the correct date conversion?