。之前和之后()

时间:2018-05-18 15:50:54

标签: java

我一直在尝试编写一个程序,它必须查看csv文件中的某个时间是在某个值之后还是之前。 但是,我收到以下错误:

javaFiles\testing.java:116: error: cannot find symbol
                                        boolean before = result.format(formatter).before(calc);
                                                                                 ^
  symbol:   method before(LocalTime)
  location: class String
javaFiles\testing.java:117: error: cannot find symbol
                                        boolean after = result.format(formatter).after(calc2);
                                                                                ^
  symbol:   method after(LocalTime)
  location: class String

这是给出问题的代码:

LocalTime calc = LocalTime.parse("06:00", formatter);
LocalTime calc2 = LocalTime.parse("17:30", formatter);

//before and after , if true its night
boolean before = result.format(formatter).before(calc);
boolean after = result.format(formatter).after(calc2);

有关完整代码,请参阅https://pastebin.com/5EGurJig,因此我不必在此处发送垃圾邮件

1 个答案:

答案 0 :(得分:2)

我不知道变量result有哪个类但你在String上调用beforeafter,因为format调用的结果是一个字符串。因此,如果result也是LocalDate,您可以使用:

boolean before = result.isBefore(calc);
boolean after = result.isAfter(calc2);