Format date in Android and SQLite

Posted on

Question :

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) {

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


Answer :

Change the line that establishes the format:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");


Leave a Reply

Your email address will not be published. Required fields are marked *