正如我的评论中所述,OLE 中的日期存储为自 1899 年 12 月 30 日以来的天数。你可以很容易地计算出这个数字。当你拥有它时,我认为使用标准变体将它传递给正确的 OLE 属性。
不幸的是,我没有在这里安装 SWT,也无法测试代码,但它应该看起来像这样
public class Test {
static Calendar OLE_BASE_DATE = Calendar.getInstance();
static {
OLE_BASE_DATE.set(1899, 11, 30); // 1899-12-30
}
static double oleDateFormat(Calendar cal) {
long diff = cal.getTimeInMillis() - OLE_BASE_DATE.getTimeInMillis();
return diff / 86400000L;
}
public static void main(String[] args) {
// get outlook instance etc...
OleAutomation appointment = invoke(outlook, "CreateItem", 1).getAutomation();
appointment.setProperty(property(appointment, "Subject"), new Variant("Test"));
// compute the appointment start & stop
double todayAtNoon = oleDateFormat(Calendar.getInstance()) + 0.5;
double todayAt13_12 = oleDateFormat(Calendar.getInstance()) + 0.55;
// set the vars
appointment.setProperty(property(appointment, "Start"), new Variant(String.valueOf(todayAtNoon)));
appointment.setProperty(property(appointment, "End"), new Variant(String.valueOf(todayAt13_12)));
appointment.setProperty(property(appointment, "Location"), new Variant("At foo's"));
// do more stuff
}
}
有关 Outlook 自动化的更多信息,请参见此处以获取 VB 中的完整示例