LocalDateTime withDayOfMonth(int dayOfMonth)
returns a copy of this LocalDateTime with the day-of-month altered.
withDayOfMonth
has the following syntax.
public LocalDateTime withDayOfMonth(int dayOfMonth)
The following example shows how to use withDayOfMonth
.
import java.time.LocalDateTime; //from w w w.j a v a 2 s .co m public class Main { public static void main(String[] args) { LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01); LocalDateTime t = a.withDayOfMonth(20); System.out.println(t); } }
The code above generates the following result.
Set day of month and year on Local date time
import java.time.LocalDateTime; /*w ww . ja va 2s. com*/ public class Main { public static void main(String[] args) { LocalDateTime timePoint = LocalDateTime.now(); LocalDateTime thePast = timePoint.withDayOfMonth(10).withYear(2010); System.out.println(thePast); } }
The code above generates the following result.