try{
//实例化一个Appointment
Appointment appointment = new Appointment(service);
//约会主题
appointment.setSubject("2012年9月财务会议");
//约会内容
MessageBody body = new MessageBody();
body.setBodyType(BodyType.Text);//文本类型
body.setText("经董事局决定,于2012年9月召开会议");
appointment.setBody(body);
//与会时间
Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
//时区设置
Collection<TimeZoneDefinition> t = service.getServerTimeZones();
TimeZoneDefinition tf = null;
for (TimeZoneDefinition timeZoneDefinition : t) {
if (timeZoneDefinition.getId().equals(cal.getTimeZone().getID())) {
System.out.println("xx="+timeZoneDefinition.getName());
tf = timeZoneDefinition;
break;
}
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = formatter.parse("2012-09-25 14:20:12");
Date endDate = formatter.parse("2012-09-25 16:20:12");
appointment.setStart(startDate);
appointment.setEnd(endDate);
appointment.setStartTimeZone(tf);
//appointment.setEndTimeZone(tf);
/**
System.out.println("Start=="+cal.getTime());
appointment.setStart(cal.getTime());
appointment.setStartTimeZone(tf);
cal.add(Calendar.DATE, 4);
System.out.println("enddate=="+cal.getTime());
appointment.setEnd(cal.getTime());
appointment.setEndTimeZone(tf);
**/
//地址
appointment.setLocation("北京海淀区会议室");
EmailAddress emails = new EmailAddress();
emails.setAddress("
ss@qq.com");
appointment.save();
appointment.forward(body, emails);
}catch(Exception e){
e.printStackTrace();
}