Calendar returns object with 1 additional month

0

I have an Android application that tests whether data stored in a database has exceeded the time limit to perform a new data capture through a particular function. I was able to add the values of the database to the Calendar object, but the object is always modified with 1 month more than what was actually passed to it.

Calendar dataBancoDor = Calendar.getInstance();

int diaDor = Integer.parseInt(dataDor.substring(0,2)); //29
int mesDor = Integer.parseInt(dataDor.substring(3,5)); //11
int anoDor = Integer.parseInt(dataDor.substring(6,10)); //2017


dataBancoDor.set(anoDor,mesDor,diaDor); // (2017,11,29)
String teste1 = String.valueOf(dataBancoDor.getTime());  // Fri Dec 29 2017

Where Dec should be Nov (month 11). What am I doing wrong?

    
asked by anonymous 02.02.2018 / 06:52

1 answer

1

The months in java range from 0 to 11. So when you pass month 11 it returns December, 0 = January, 1 = February, and so on.

    
02.02.2018 / 11:35