3

我正在使用实现 google-rfc-2445 ( https://code.google.com/p/google-rfc-2445/ ) 来生成应该在事件之后重复的日期,而不是作为规则指示 ( RRULE) 重复完成还要记下时间,即下次我也扔的时候计算日期。

example:
Start Date: 17/04/2013 8:30 a.m.
Rule: "RRULE: FREQ = DAILY; UNTIL = 20130430T083000Z, INTERVAL = 1"
Expected Result, Next Repetition: 4/18/2013 8:30 a.m.
Result Obtained, Next Repetition: 4/18/2013 00 00 00

这是我正在使用的代码

 LocalDate start = new LocalDate(System.currentTimeMillis());

            String ical = "RRULE:FREQ=DAILY;"
                    + "UNTIL=20130430T083000Z;"
                    + "INTERVAL=1;";

            //Next Notification
            Date f = null;

            for (LocalDate date
                    : LocalDateIteratorFactory.createLocalDateIterable(ical, start, false)) {
                 f  = date.toDateTimeAtCurrentTime().toLocalDate().toDate();
                break;
            }

            System.out.println("Next = " + f);

打印结果为 Next = Wed Apr 17 00:00:00 COT 2013

是“BYHOUR = 8; BYMINUTE = 05; BYSECOND = 10”的存在,而不是如何使用它,如果我能伸出援手,谢谢。

4

1 回答 1

4

LocalDateIteratorFactory produces dates without a corresponding time, but it sounds like you want DateTimes. Use DateTimeIteratorFactory instead.

Also,

LocalDate start = new LocalDate(System.currentTimeMillis());

is probably not equivalent to

Start Date: 17/04/2013 8:30 a.m.

You probably want to use DateTime

DateTime start = new DateTime(2013, 4, 17, 8, 30, 0);

Finally, there's no reason to use the Joda time compatibility layer if what you want at the end is

Date f = null;

Just use the java.util compatibility layer instead.

I would suggest sticking to Joda time though, since java.util dates are a mess.

于 2013-04-17T19:32:05.743 回答