Ramadan is the 9th month of the Islamic calendar, the entire month.
1. HijrahDate -> Ramadan 2016
Full example to calculate the start and end of the Ramadan 2016
TestHijrahDate.java
package com.favtuts.time;
import java.time.LocalDate;
import java.time.chrono.HijrahDate;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
public class HijrahDateRamadan {
public static void main(String[] args) {
convertHijrahDateToRamadan2016();
}
static void convertHijrahDateToRamadan2016() {
//first day of Ramadan, 9th month
HijrahDate ramadan = HijrahDate.now()
.with(ChronoField.DAY_OF_MONTH, 1).with(ChronoField.MONTH_OF_YEAR, 9);
System.out.println("HijrahDate : " + ramadan);
//HijrahDate -> LocalDate
System.out.println("\n--- Ramandan 2016 ---");
System.out.println("Start : " + LocalDate.from(ramadan));
//until the end of the month
System.out.println("End : " + LocalDate.from(ramadan.with(TemporalAdjusters.lastDayOfMonth())));
}
}
Output
HijrahDate : Hijrah-umalqura AH 1443-09-01
--- Ramandan 2016 ---
Start : 2022-04-02
End : 2022-05-01
Download Source Code
$ git clone https://github.com/favtuts/java-core-tutorials-examples
$ cd java-basic/time