RRULE google-rfc-2445有小时和秒

时间:2013-04-17 19:27:12

标签: java jodatime rfc2445 rrule rfc5545

我正在使用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”而不是如何使用它,如果我能伸出援手,谢谢。

1 个答案:

答案 0 :(得分:4)

LocalDateIteratorFactory生成没有相应时间的日期,但听起来你想要DateTimes。请改用DateTimeIteratorFactory

此外,

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

可能不等同于

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

您可能想要使用DateTime

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

最后,没有理由使用Joda时间兼容性层,如果你想要的最终是

Date f = null;

只需使用java.util compatibility layer

我建议坚持Joda时间,因为java.util日期很糟糕。

相关问题