Pass parameter date to an Android calendar

1

I am showing in a calendar the events that I have in my DB but I do not know how to pass a date parameter.

        Calendar calendar1 = Calendar.getInstance();
    calendar1.add(calendar.DAY_OF_YEAR, 3);//Aqui esta la posicion, (dia en el que quiero que se refleje el titulo del evento)
    events.add(new EventDay(calendar1, DrawableUtils.getCircleDrawableWithText(this, "titulo del evento")));

The problem is that I want to replace that line with something like that,

fecha=2018-12-19;
        Calendar calendar1 = Calendar.getInstance();
    calendar1.add(fecha);
    events.add(new EventDay(calendar1, DrawableUtils.getCircleDrawableWithText(this, "Nombre del evento")));

I hope you understand what I need to do ...

    
asked by Wilson Cajisaca 19.12.2018 в 18:15
source

1 answer

1

If you want to pass the fecha=2018-12-19; to Calendar , first you have to make a parse of String to Calendar , try the following:

fecha = "2018-12-19";
Calendar calendar1 = Calendar.getInstance();
SimpleDateFormat convertirFecha = new SimpleDateFormat("YYYY-MM-DD"); //Estableces el formato de la fecha

try {//Haces un try/catch por si ocurre un exception
     calendar1.setTime(convertirFecha.parse(fecha)); //haces la conversión
} catch (ParseException e) {
     e.printStackTrace();
}
    
answered by 20.12.2018 / 18:35
source