Format date in Android and SQLite

3

I am having difficulty setting the current date of my SQLite database in the% type attribute of my object.

The SQLite date comes in the format "yyyy-MM-dd". I'm trying to convert to the format accepted in type java.util.Date and that allows me to use it in my Adapter but when running the application is returning me an error saying that the date is null. Actually when I debugged the App I saw that the date is not being set.

Follow the part of the code.

        Date data = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String dataTeste = cursor.getString(1);
        try {
            data = dateFormat.parse(dataTeste);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        v.setDataVenda(data);

Note: In the variable java.util.Date the value that is being filled is "2015-11-15".

    
asked by anonymous 15.11.2015 / 06:27

1 answer

4

Change the line that establishes the format:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    
15.11.2015 / 08:04