如何在Outlook中阅读今天的电子邮件

时间:2019-05-09 12:06:23

标签: java outlook javamail

我正在尝试仅使用javax.mail api阅读我今天收到的电子邮件。

DataValue.objects.order_by('period_quarter','period_year').distinct('period_quarter','period_year')

即使我的收件箱中有上述代码,也不会返回任何电子邮件。

3 个答案:

答案 0 :(得分:1)

似乎Date的构造函数采用了long,它表示从1970年1月1日起的毫秒数。但是,Calender.DAY_OF_MONTH似乎只返回表示月份中的某天的整数。 。我建议使用诸如System.currentTimeMillis()之类的东西以毫秒为单位得出日期。

参考文献:

https://docs.oracle.com/javase/8/docs/api/java/util/Date.html#Date-long-

https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#currentTimeMillis--

What's the difference between adding DAY_OF_MONTH or DAY_OF_YEAR to a Calendar object?

答案 1 :(得分:0)

您可以尝试

ReceivedDateTerm term = new ReceivedDateTerm(ComparisonTerm.EQ,new Date(Calendar.getTime()));

SimpleDateFormat format= new SimpleDateFormat( "MM/dd/yy" );
java.util.Date dDate = format.parse("01/01/19");
SearchTerm st = new ReceivedDateTerm(ComparisonTerm.EQ,dDate );

答案 2 :(得分:0)

注意:我 不了解JavaMail,也不了解ReceivedDateTerm的确切行为。但是我确实知道日期时间处理。如果目标是确定今天的第一刻,请继续阅读。

一天的第一时刻

您的日期时间处理不正确。

现代方法使用JSR 310中定义的 java.time 类。

获取当前日期需要一个时区。在任何给定时刻,日期都会在全球范围内变化。

ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
LocalDate today = LocalDate.now( z ) ;

确定第一时刻。时间不一定是00:00:00,因为某些区域中的某些日期是从其他时间(例如01:00:00)开始的。

ZonedDateTime zdt = today.atStartOfDay( z ) ;

提取Instant以适应UTC。同一时刻,时间轴上的同一点,不同的时钟时间。

Instant instant = zdt.toInstant() ;

constructor for ReceivedDateTerm带有一个java.util.Date对象,尚未更新为现代的 java.time 框架。

从我们的现代Instant转换为可怕且命名错误的旧类java.util.Date

Date d = Date.from( instant ) ;

d传递到JavaMail代码作为搜索的开始时刻。