5

Any enum to associate below months?

1 Muharram
2 Safar
3 Rabi\u02bb I
  Rabi\u02bb II
  Jumada I
  Jumada II
  Rajab
  Sha\u02bbban
  Ramadan
  Shawwal
  Dhu\u02bbl-Qi\u02bbdah
  Dhu\u02bbl-Hijjah
Andreas
  • 154,647
  • 11
  • 152
  • 247

1 Answers1

2

Take a look at Time4j library, calendar project.

Maven dependency:

<dependency>
    <groupId>net.time4j</groupId>
    <artifactId>time4j-calendar</artifactId>
    <version>4.24</version>
</dependency>

Example:

Stream.of(HijriMonth.values()).forEach(v->
            System.out.println("Display name: " + v.getDisplayName(Locale.US) + " month index: " + v.getValue()));

Output:

Display name: Muharram month index: 1
Display name: Safar month index: 2
Display name: Rabiʻ I month index: 3
Display name: Rabiʻ II month index: 4
Display name: Jumada I month index: 5
Display name: Jumada II month index: 6
Display name: Rajab month index: 7
Display name: Shaʻban month index: 8
Display name: Ramadan month index: 9
Display name: Shawwal month index: 10
Display name: Dhuʻl-Qiʻdah month index: 11
Display name: Dhuʻl-Hijjah month index: 12
Enigo
  • 3,685
  • 5
  • 29
  • 54
  • Thx but don't want to depend on other library thought to do same using java 1.8+ api – sajidbigler Feb 19 '17 at 17:47
  • 1
    As far as I can tell there is no built-in enum in Java, although there now a bunch of usefull classes in java 8 like `HijrahChronology`, `HijrahDate`, `HijrahEra`. If you don't want to use other libraries then you should write your own enum. But it might be difficult after all) – Enigo Feb 19 '17 at 18:26