Home > Software engineering >  How to set LocalDate in IntelliJ Java IDEA debugger
How to set LocalDate in IntelliJ Java IDEA debugger

Time:12-14

I am trying to modify (with F2 - set value) a variable of type LocalDate in JetBrains IntelliJ IDEA debugger, but I am getting a "Type mismatch" error. Is there a possibility to do this?

CodePudding user response:

Yes, you can do it. Instead of entering a String value or a number, you can also enter Java expressions in IntelliJ debugger. So to set LocalDate variable, the easiest way would be to enter this expression in the "Set variable" input box:

LocalDate.parse("2021-12-28", DateTimeFormatter.ofPattern("yyyy-MM-dd"))

CodePudding user response:

In any time zone

    public String dateFormater(String dateTime) {
    try {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        f.setTimeZone(TimeZone.getTimeZone("UTC"));
        return f.format(f.parse(dateTime));
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return "";
}
  • Related