Issue
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.
Solution
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
Answered By - Ole V.V.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.