i'm new in Android and I want to parse a string with a date to convert it to a calendar object and then send it to the Android Calendar. My string value is Jue 28-05-2015 22:30 (Jue for Jueves, thursday in spanish) and my code looks like this:
fechaevento = Calendar.getInstance();
beginTime ="Jue 28-05-2016 22:30"
final SimpleDateFormat sdf = new SimpleDateFormat("EEE dd-MM-yyyy kk:mm");
btnCalendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
fechaevento.setTime(sdf.parse(beginTime));
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, fechaevento.getTimeInMillis())
.putExtra(CalendarContract.Events.TITLE, nameEvento.getText().toString())
.putExtra(CalendarContract.Events.DESCRIPTION, descriptionEvento.getText().toString());
startActivity(intent);
} catch (ParseException e) {
//e.printStackTrace();
Log.i("FECHA_M", e.getMessage());
}
}
});
When I try to run it i get the error: Unparseable date: "Jue 28-05-2016 22:30" (at offset 0)
Pass the Spanish Locale to your date formatter: