Firstly, separate out the conversion part from the formatting/parsing part. You can deal with those easily later - and there are lots of questions on Stack Overflow about that.
Personally I'd use Joda Time, which typically makes life much simpler. For example:
import org.joda.time.Chronology;
import org.joda.time.LocalDate;
import org.joda.time.chrono.IslamicChronology;
import org.joda.time.chrono.ISOChronology;
public class Test {
public static void main(String[] args) throws Exception {
Chronology iso = ISOChronology.getInstanceUTC();
Chronology hijri = IslamicChronology.getInstanceUTC();
LocalDate todayIso = new LocalDate(2013, 3, 31, iso);
LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(),
hijri);
System.out.println(todayHijri); // 1434-05-19
}
}
(It feels like there should be a cleaner way of converting dates between chronologies, but I couldn't find one immediately.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…