Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
how I can get the date in tjava for the first Sunday of January and the first Sunday of July?
I need these dates in order to compare the current date.
Thanks for any hints.
Hello,
You could try writing your own routine to work out the 1st Sunday.
For example
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
public class GFG {
public static void pring(int year, int month, int day)
{
// get TemporalAdjuster with
// the first in month adjuster
TemporalAdjuster temporalAdjuster
= TemporalAdjusters.firstInMonth(
DayOfWeek.SUNDAY);
// using adjuster for local date time
LocalDate localDate
= LocalDate.of(year, month,day);
LocalDate firstInMonth
= localDate.with(temporalAdjuster);
System.out.println(
"First date in month having"
+ " sunday for localdate "
+ localDate + " is:"
+ firstInMonth);
}
}
Please have a look at my screenshots for details and let us know if it is OK with you.
Best regards
Sabrina