Ilja
Ilja

Reputation: 46479

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"

Upvotes: 4

Views: 15846

Answers (1)

Luca Sepe
Luca Sepe

Reputation: 2445

You should use SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String selectedDate = sdf.format(new Date(calendar.getDate()));

Upvotes: 9

Related Questions