Calendar returns object with an additional 1 month

Asked

Viewed 38 times

0

I have an Android app that tests whether the dates stored in bank exceeded the time limit to perform a new data capture through a certain 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 is Dec should be Nov (month 11). What I’m doing wrong?

1 answer

1


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.