iCalendar字符串到日历

时间:2014-03-05 13:55:50

标签: android icalendar

我有一个iCalendar格式字符串,如下所示: http://en.wikipedia.org/wiki/ICalendar 我想在Calendar对象中进行转换。 我怎样才能做到这一点?我必须自己解析字符串,或者有一些方法可以解决这个问题吗?

编辑: 最后我做了这个解决方案:

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
String[] split=s.split("\n|(:)");
                for(int i=0;i<split.length;i++){
                    if(split[i].contains("DTSTART")){
                        //next String contain the data start
                        String s1=split[i+1];
                        s1=s1.replace("T", "");//remove T
                        s1=s1.replace("00Z", "");//remove final part
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
                        Date date;
                        try {
                            date = sdf.parse(s1);
                            Log.d("", "START "+date.getTime());
                            intent.putExtra("beginTime",date.getTime());
                        } catch (ParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                    }

                    if(split[i].contains("DTEND")){
                        //next string contains the data end
                        String s1=split[i+1];
                        s1=s1.replace("T", "");//remove T
                        s1=s1.replace("00Z", "");//remove final part
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
                        Date date;
                        try {
                            date = sdf.parse(s1);
                            Log.d("", "END "+date.getTime());
                            intent.putExtra("endTime", date.getTime());
                        } catch (ParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                    if(split[i].contains("LOCATION")){
                        //next string contains location
                        Log.d("", "Luogo "+split[i+1]);
                        intent.putExtra("eventLocation",split[i+1]);

                    }

                    if(split[i].contains("DESCRIPTION")){
                        //next string contains location
                        Log.d("", "Descrizione "+split[i+1]);
                        intent.putExtra("description",split[i+1]);

                    }

                    if(split[i].contains("SUMMARY")){
                        //next string contains title
                        Log.d("", "Titolo "+split[i+1]);
                        intent.putExtra("title",split[i+1]);

                    }

                }
startActivity(intent);

1 个答案:

答案 0 :(得分:0)

您可以查看iCal4j库here。它可能对你有帮助。