在Java代码中为Outlook约会设置开始日期和结束日期的日期格式 [英] Date format for setting start and end date to Outlook appointment in java code
问题描述
我正在通过Java代码在Outlook中创建约会.在这里,我可以为约会中的字段设置新值.它的代码是
I am creating an appointment in Outlook through java code. here I can set new values to the fields in appointment. The code for it is
OleAutomation appointment = invoke(outlook, "CreateItem", 1).getAutomation();
appointment.setProperty(property(appointment, "Subject"), new Variant("Test"));
此代码会将主题字段设置为值"Test".
this code will set the subject field with the value "Test".
在这里,我使用通用的OLE机制"Variant"来通过一个公共接口传递不同类型的数据现在,我想知道如何设置约会的日期.请帮助我.
here i am using generic OLE mechanism "Variant" for passing data of different types via a common interface Now I want to know how to set a date for the appointment. Please help me..
先谢谢您了:)
推荐答案
如我的评论所述,OLE中的日期存储为自1899-12-30开始的天数.您可以轻松地计算出该数字.有了它后,请使用我认为的标准变体将其传递到正确的OLE属性.
As stated in my comment, the date in OLE are stored as the number of days since 1899-12-30. You can calculate that number easily. When you have it, pass-it to to the right OLE property using standard variant I think.
不幸的是,我没有在这里安装SWT,也无法测试代码,但是看起来应该像这样
Unfortunately I don't have SWT installed here and can't test the code, but it should look something like that
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中的完整示例
More info on the automation of Outlook can be found here for a complete example in VB
这篇关于在Java代码中为Outlook约会设置开始日期和结束日期的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!