Date format for setting start and end date to Outlook appointment in java code

风流意气都作罢 提交于 2019-12-25 08:24:27

问题


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"));

this code will set the subject field with the value "Test".

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..

Thanks in advance :)


回答1:


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.

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
    }
}

More info on the automation of Outlook can be found here for a complete example in VB



来源:https://stackoverflow.com/questions/9733254/date-format-for-setting-start-and-end-date-to-outlook-appointment-in-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!