我是Android的新手,我想解析一个带有日期的字符串,将其转换为日历对象,然后将其发送到Android日历。我的字符串值为Jue 28-05-2015 22:30(Jue for Jueves,星期四为西班牙语),我的代码如下所示:

    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());
            }
        }
    });


当我尝试运行它时,出现错误:无法解析的日期:“ Jue 28-05-2016 22:30”(偏移量为0)

最佳答案

将西班牙语语言环境传递给您的日期格式器:

final SimpleDateFormat sdf =
    new SimpleDateFormat("EEE dd-MM-yyyy kk:mm", new Locale("es"));

10-08 10:52