1

I'm using time4A to do transformation from Islamic Hjiri to Gregorian Date and vice versa. I'm not able to find a way to format Hijri Date to "yyyy/mmm/dd" pattern.

Here is the code to convert from Gregorian to Hijri :

     CalendarVariant variant =
                    PlainDate.of(2016, 02, 12)
                            .transform(HijriCalendar.class, HijriCalendar.VARIANT_UMALQURA);

System.out.println(variant.toString());

I got this AH-1437-05-03[islamique-umalqura]

I need some thing like: 1437-05-03

So, How I can format Hijri Date ?

Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126
abdou amer
  • 819
  • 2
  • 16
  • 43

1 Answers1

0

Sorry for late answer. If you don't get an immediate reply you could also ask the question directly on the issue tracker of Time4J.

About your question, two points:

a) Don't use abstract interface types but concrete types. Here, replace CalendarVariant by HijriCalendar, otherwise you will handle a raw type due to unresolved generics.

b) The formatter class ChronoFormatter can handle formatting (and parsing as well). You only need to feed it with following informations: pattern string, pattern type, locale and chronology. It is also immutable and can be stored in a static final constant. Example:

HijriCalendar hijriDate =
    PlainDate.of(2016, 02, 12).transform(
        HijriCalendar.class,
        HijriCalendar.VARIANT_UMALQURA
    );
ChronoFormatter<HijriCalendar> hf =
    ChronoFormatter.ofPattern(
        "yyyy-MM-dd", // mmm as given by you would be in minutes in CLDR-standard
        PatternType.CLDR,
        Locale.ROOT,
        HijriCalendar.family()
    );
System.out.println(hf.format(hijriDate)); // 1437-05-03

The given example just uses the root locale because you only want a numerical representations using standard digits. But of course you can have a formatted representation using other numerical systems if you want (then the locale matters, or you even set an explicit format attribute).

Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126