Error to parse date: “Unparseable date: ”Jue 28-05-2016 22:30“ (at offset 0)”

旧城冷巷雨未停 提交于 2019-12-14 04:21:19

问题


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)


回答1:


Pass the Spanish Locale to your date formatter:

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


来源:https://stackoverflow.com/questions/31885939/error-to-parse-date-unparseable-date-jue-28-05-2016-2230-at-offset-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!