I want to display the Ramadan 2017 start and end dates. I tried writing code using the HijrahChronology
built into Java 8 and later, with HijrahDate
class.
import java.time.LocalDate;
import java.time.chrono.HijrahDate;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
public class Ramdan {
public static void main(String[] args) {
HijrahDate ramdanDate = HijrahDate.now().with(ChronoField.DAY_OF_MONTH, 1).with(ChronoField.MONTH_OF_YEAR, 9);
LocalDate ramdanStart = LocalDate.from(ramdanDate);
LocalDate ramdanEnd = LocalDate.from(ramdanDate.with(TemporalAdjusters.lastDayOfMonth()));
System.out.println("Ramdan 2017");
System.out.println(ramdanStart);
System.out.println(ramdanEnd);
}
}
But it obviously prints out the dates for current year, i.e., 2018.
Output
Ramdan 2017
2018-05-16
2018-06-14
I tried many things like minus years, or doing temporal adjustments but nothing helped. Can someone suggest a cool way of achieving it?