关于事件问题的开始和结束领域,从Android的日历的阅读事件有问题。
代码:
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final MyActivity self = this;
Button button = (Button) this.findViewById(R.id.ReadButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ContentResolver contentResolver = self.getContentResolver();
Uri uri = Uri.parse("content://com.android.calendar/instances/when");
Uri.Builder builder = uri.buildUpon();
//Range filter
Calendar from = Calendar.getInstance();
from.setTime(new Date());
from.set(Calendar.HOUR,0);
from.set(Calendar.MINUTE,0);
from.set(Calendar.SECOND,0);
from.set(Calendar.MILLISECOND, 0);
Calendar to = Calendar.getInstance();
to.setTime(from.getTime());
to.set(Calendar.HOUR,11);
to.set(Calendar.MINUTE,59);
to.set(Calendar.SECOND,59);
to.set(Calendar.MILLISECOND, 997);
ContentUris.appendId(builder, from.getTime().getTime());
ContentUris.appendId(builder, to.getTime().getTime());
Cursor cursor = contentResolver.query(builder.build(), new String[] {"_id", "title", "begin", "end", "allDay"}, "calendar_id=1", null, "startDay ASC, startMinute ASC");
if(cursor.getCount()>0) {
while (cursor.moveToNext()) {
final String title = cursor.getString(1);
final Date begin =new Date(cursor.getLong(2));
final Date end = new Date(cursor.getLong(3));
Log.i("ReadCalendar", title);
Log.i("ReadCalendar", begin.toString());
Log.i("ReadCalendar", end.toString());
}
}
}
});
}
}
我在Google日历中创建了一个事件,以下是详细信息
日期:2013年7月1日
标题:香港特别行政区成立日
全天活动:检查
单击按钮时,“流动”是“日志窗口”
的结果07-01 16:52:06.491: INFO/ReadCalendar(1357): Hong Kong Special Administrative Region Establishment Day<br/>
07-01 16:52:06.491: INFO/ReadCalendar(1357): **Mon Jul 01 08:00:00 GMT+08:00 2013**<br/>
07-01 16:52:06.501: INFO/ReadCalendar(1357): **Tue Jul 02 08:00:00 GMT+08:00 2013**<br/>
问题是为什么我得到了开始和结束日是错误的。它应该是2013年7月1日00:00:00至2013年7月1日23-59:59
但是日历中显示的此事件是正确的。
请帮助!!!!