Joda-Time Formatting for Islamic Date

date, java, jodatime

Solution

This is currently not implemented. The BasicChronology class sets the monthOfYear field to use GJMonthOfYearDateTimeField which in turn gets it's data from java.text.DateFormatSymbols. The IslamicChronology uses a sets the monthOfYear field to a BasicMonthOfYearDateTimeField which has the following implementation of getAsText:

public String getAsText(int fieldValue, Locale locale) {
    return Integer.toString(fieldValue);
}

What someone needs to do is to create a IslamicMonthOfYearDateTimeField that extends BasicMonthOfYearDateTimeField and overrides the method so that it returns the name of the month rather than the numeric value of the month. This could either be done in the joda-time codebase, or completely outside. To get this working outside of joda, just extend IslamicChronology and override assemble to pull in your new IslamicMonthOfYearDateTimeField. I'd issue a pull request to joda-time myself, but I doubt they'd accept a non-localized solution.

Problem

I am using Joda-Time to get the Islamic date in the dd MMMM yyyy but I am always getting dd MM yyyy. Any advise? could it be that Hijri dates are not supported for formatting? It's not clear on the Joda-Time website. ``` DateTime dtISO = new DateTime(2014,2,25,0,0,0,0); DateTime dtIslamic = dtISO.withChronology(IslamicChronology.getInstance()); String formatIslamic= "dd MMMM yyyy"; DateTimeFormatter formatter = DateTimeFormat.forPattern(formatIslamic).withChronology( IslamicChronology.getInstance()); String islamicDateString = formatter.print(dtIslamic); ```

Original source

Related problems