将日期和时间添加到事件日历android

时间:2013-12-10 03:34:55

标签: android

我正在我的日历中创建活动到我的Android设备。以下是我通过互联网搜索的代码。

public void onClick(View arg0) {
    long startTime = getMilliSeconds(startDate) + 1000 * 60 * 60;  
    long endTime = getMilliSeconds(endDate) + 1000 * 60 * 60 *2; 

    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra("beginTime", startTime );
    intent.putExtra("allDay", true);
    intent.putExtra("endTime", endTime);
    intent.putExtra("title", ""+mytitle);
    startActivity(intent);
}

public long getMilliSeconds(String date) throws ParseException{
    Date dateSample = null ; 
    try {  
        //2013-12-28 23:30:00
        SimpleDateFormat formatter ;       
        formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateSample = (Date) formatter.parse(date);  
    } catch (Exception e) {
    }
    return dateSample.getTime();
}

它工作正常,但创建事件时没有显示时间。只显示月份日和年份。现在,我想在创建活动时花时间展示。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

你把它设定为一整天:

intent.putExtra("allDay", true);

如果你删除该行,它应该可以工作。