Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date from calendarView() onCreate, with a specific format e.g. DD/MM/YYYY?

I'm trying to get a date from calendar view:

calendar = (CalendarView) findViewById(R.id.calendarView);

by trying:

String selectedDate = calendar.getDate().toString();

But am getting error saying that toString() method can not be resolved I would like to further get it in a format of "DD/MM/YYYY"

like image 363
Ilja Avatar asked Feb 13 '23 11:02

Ilja


1 Answers

You should use SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String selectedDate = sdf.format(new Date(calendar.getDate()));
like image 142
Luca Sepe Avatar answered Feb 16 '23 04:02

Luca Sepe