tes*_*123 14 java datetime jodatime
有没有办法只使用isBefore函数比较DateTime对象的日期?
例如,
DateTime start = new DateTime(Long.parseLong(<someInput>));
DateTime end = new DateTime(Long.parseLong(<someInput>));
Run Code Online (Sandbox Code Playgroud)
现在当我这样做的时候
while (start.isBefore(end)) {
// add start date to the list
start = start.plusDays(1);
}
Run Code Online (Sandbox Code Playgroud)
这会导致行为不一致(对于我的场景),因为它也考虑了时间,而我想要的只是使用isBefore比较日期.有没有办法可以做到这一点?
请告诉我.
谢谢!
另一个策略是格式化它.
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
DateTime newStart = df.parse(start);
DateTime newEnd = df.parse(end);
while (newStart.isBefore(newEnd)) {
// add start date to the list
newStart = newStart.plusDays(1);
}
Run Code Online (Sandbox Code Playgroud)