0

Basically, I want to get the date of Monday from the current day of the week. eg: today is Tuesday and I want a Monday date, I'll get that required date from the following code lines:

 val now = LocalDate()
 val monday: LocalDate = now.withDayOfWeek(DateTimeConstants.MONDAY)
        mondayDate = monday.toString()
       

But the problem is that I'm getting date format as 2021-05-24 and I want the date in such format 24-5-2021. Now how to change the date format to get the required date format.

Prajna Rai T
  • 1,666
  • 3
  • 15

1 Answers1

0

What you need is a formatter.

    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("d-M-y");
    
    LocalDate now = new LocalDate();
    LocalDate monday = now.withDayOfWeek(DateTimeConstants.MONDAY);
    String mondayDate = monday.toString(dateFormatter);
    System.out.println(mondayDate);

Output is what you asked for:

24-5-2021

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161