DateTime无法转换为Date

时间:2016-08-18 08:52:26

标签: java datetime

我想从Outlook日历中获取今天的所有活动:

public void findAppointmentsToday(String outlook_url, String username, String password) throws Exception
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        ExchangeCredentials credentials = new WebCredentials(username, password);

        URI url = URI.create("https://outlook.com/ews/Exchange.asmx");
        service.setUrl(url);
        service.setTraceEnabled(true);
        service.setCredentials(credentials);

//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date startDate1 = formatter.parse(start_date);
//        Date endDate1 = formatter.parse(end_date);

        Date currentDate = new Date();
        DateTime start = new DateTime(DateTimeUtil.getDateBeginning(currentDate));
        DateTime end = new DateTime(DateTimeUtil.getDateEnding(currentDate));

        CalendarFolder cf = CalendarFolder.bind(service, WellKnownFolderName.Calendar);
        FindItemsResults<Appointment> findResults = cf.findAppointments(new CalendarView(start, end));

        for (Appointment appt : findResults.getItems())
        {
            System.out.println("Start :" + appt.getStart());
            System.out.println("End :" + appt.getEnd());
            System.out.println("Subject :" + appt.getSubject());
            System.out.println("AppointmentType :" + appt.getAppointmentType().name());
            System.out.println("Location :" + appt.getLocation());
            System.out.println("Duration :" + appt.getDuration().getMinutes());
            System.out.println("Email Address: " + appt.getOrganizer().getAddress());
            System.out.println("Last Modified Time: " + appt.getLastModifiedTime());
        }
    }

我尝试使用这个Java类来获取今天的事件范围:

import java.util.Calendar;
import java.util.Date;

public class DateTimeUtil
{
    public static Date getDateBeginning(Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
    }

    public static Date getDateEnding(Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);

        return calendar.getTime();
    }
}

在这一行,我收到错误:

cf.findAppointments(new CalendarView(start,end));

incompatible types: DateTime cannot be converted to Date

我可以以某种方式解决这个问题吗?

0 个答案:

没有答案