1

I'm trying to add 2 weeks to date in java.

I currently use following code, it gives me today's date correctly but it gives me an error in 2 weeks date. I have attached a screenshot of the error. Any ideas on fixing this.

    void Days() {
    String today = LocalDate.now().toString();
    System.out.println(today);
    lbl_borrowdate.setText(today);

    //add 2 week to the current date
    LocalDate next2Week = today.plus(2, ChronoUnit.WEEKS);
    System.out.println(next2Week);
    lbl_duedate.setText(next2Week);
}

Error

  • 1
    LocalDate today = LocalDate.now(); System.out.println(today); //add 2 week to the current date LocalDate next2Week = today.plus(2, ChronoUnit.WEEKS); System.out.println(next2Week); – strash Apr 13 '17 at 17:27
  • 1
    your first line of code should look like: LocalDate today = LocalDate.now(); – strash Apr 13 '17 at 17:28
  • But I need to assign them to these lbl_borrowdate, lbl_duedate These are two labels – Dilum Jayawardhana Apr 13 '17 at 17:30
  • 2
    @gen.Strash sorry. The OP is using variables that simply don't exist. He's got bigger problems than how to use LocalDate, fundamental how to code simple variable problems. – Hovercraft Full Of Eels Apr 13 '17 at 17:31
  • 1
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy"); String formattedString = yourDateObject.format(formatter); – strash Apr 13 '17 at 17:36
  • I manged to get this to work, thanks for your help. I'm a newbie to programming, so people like @HovercraftFullOfEels should remember that everyone is not fluent in coding. I've still got lot to learn. Anyway thanks for the help, really appreciate it. – Dilum Jayawardhana Apr 13 '17 at 17:47

0 Answers0