我是 Android 新手,我想解析一个带日期的字符串,将其转换为日历对象,然后将其发送到 Android 日历。我的字符串值为Jue 28-05-2015 22:30(Jue for Jueves,thursday in spanish),我的代码如下所示:
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)