tl;dr
LocalDate.parse(
"15/12/2016" ,
DateTimeFormatter.ofPattern( "dd/MM/uuuu" )
).with(
TemporalAdjusters.next( DayOfWeek.MONDAY )
)
java.time
You are using troublesome old date-time classes, now legacy, supplanted by java.time classes.
LocalDate
The LocalDate
class represents a date-only value without time-of-day and without time zone.
LocalDate ld = LocalDate.parse( "15/12/2016" , DateTimeFormatter.ofPattern( "dd/MM/uuuu" ) );
The java.time classes use immutable objects. So rather than change (“mutate”) the value in an existing object, we instantiate a new object based on the original’s values. One way to do this is with an implementation of a TemporalAdjuster
.
LocalDate nextMonday = ld.with( TemporalAdjusters.next( DayOfWeek.MONDAY ) ) ;
The classes have been discussed many times. So search Stack Overflow for more info.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8 and SE 9 and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android