本文介绍了解析日期错误:“不可解析的日期:” Jue 28-05-2016 22:30” (在偏移量0处)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

当我尝试运行它时出现错误:无法解析的日期: 2016年5月28日22:30(偏移量为0)

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:

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

这篇关于解析日期错误:“不可解析的日期:” Jue 28-05-2016 22:30” (在偏移量0处)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 02:47