Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getYear(), getMonth(), getDay are deprecated in Calendar, what to use then?

I want to parse a date from a string and set it in the DatePickerDialog:

try {
    myCalendar.setTime(mySimpleFormatter.parse(jsonObj.getString("dob")));
} catch (ParseException e) {
    System.out.println("!!!");
}

myEditBox.setText(mySimpleFormatter.format(myCalendar.getTime()));
myDatePickerDialog.getDatePicker().updateDate(myCalendar.getTime().getYear()); // depricated

But the issue is that myCalendar.getTime().getYear(), getMonth(), getDay are deprecated. What should be used then?

like image 743
Alan Coromano Avatar asked Apr 02 '16 08:04

Alan Coromano


1 Answers

Calendar cal = Calendar.getInstance();
cal.setTime(myDate);
int day= cal.get(Calendar.DAY_OF_MONTH);
like image 104
Pablo Cegarra Avatar answered Nov 15 '22 18:11

Pablo Cegarra