问题描述
我正在尝试在某个时间戳记之后获取消息,该代码的编码方式是由该站点的另一位程序员建议的:
I'm trying to get messages after a certain time-stamp, the way I've coded it was suggested by another programmer in this site:
GregorianCalendar date = new GregorianCalendar();
SearchTerm newer = new ReceivedDateTerm(ComparisonTerm.GT,date.getTime());
Message msgs[] = folder.search(newerThen);
问题是我收到了自日期以来的所有消息,而不是特定时间.我想知道是否有一些变通办法来模拟这一点.我的意思是,例如,如果我想获取今天中午以来的所有消息,我会特别收到这些消息,而不是今天早上收到的那些消息.
The issue is that I get all the messages since the date, not the specific time. I was wondering if there is some work-around to emulate this. I mean, for an instance, if I want to get all the messages since today in the midday I would get those messages spicifically and not those ones received in today's morning.
预先感谢
与此有关的一个新思路:也许一些日期操纵可以完成这项工作.我的意思是,比较时间戳记中的分钟数,并以编程方式过滤那些不符合条件的消息.我知道这不是最好的方法,但是它可以工作.
A new thought concerning to this: perhaps some date manipulation could do the job. I mean, comparing the minutes in the timestamp and filter programmatically those messages that don't fit the criteria. I know it's not the best way, but it could work.
PS:我正在使用IMAP并尝试从gmail获取邮件,但是我认为无论邮件服务器是什么,它都应该起作用.
PS: I'm using IMAP and trying to get mails from gmail, but I guess it should work no matter what the mail-server is.
推荐答案
不幸的是,没有.在这种情况下,JavaMail类正在使用IMAP协议,而IMAP的SEARCH
命令仅获取日期,而不获取时间(请参见SINCE
和SENTSINCE
标准).
Unfortunately, no. In this case, the IMAP protocol is being used by the JavaMail classes, and IMAP's SEARCH
command takes only dates, not times (see the SINCE
and SENTSINCE
criteria).
这篇关于JavaMail:如何获取与时间戳进行比较的新消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!