解析日期时出错:"无法解析日期:" Jue 28-05-2016 22:30" (在偏移0处)"

时间:2015-08-07 20:15:35

标签: android date simpledateformat unparseable

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

当我尝试运行它时,我收到错误:Unparseable date:" Jue 28-05-2016 22:30" (在偏移0处)

1 个答案:

答案 0 :(得分:3)

将西班牙语区域设置传递给日期格式化程序:

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