Get Month Name of java.time.chrono.HijrahDate instance
Asked Answered
P

3

7
HijrahDate hd=HijrahChronology.INSTANCE.date(LocalDate.of(2014,11, 25));

If we have HijrahDate Instance , it is expected to have a method in UmalquraCalendar API that shows the name of month :

i inspect properties of this instance using groovy API :

['era':AH, 
'class':class java.time.chrono.HijrahDate, 
'prolepticMonth':17233,
 'eraValue':1,
 'dayOfWeek':2,
 'leapYear':false, 
'chronology':Hijrah-umalqura, 
'dayOfYear':32] 

However we don't find the month name which must be one of the following list items :

  1. Muḥarram (محرم meaning "forbidden"), so called because battle was forbidden (haram) during this month. Muharram includes the Day of Ashura.
  2. Ṣafar (صفر meaning "void"), supposedly named thus because pagan Arab houses were empty this time of year while their occupants gathered food.
  3. Rabīʿ I (Rabīʿ al-Awwal, ربيع الأوّل) meaning "the first spring".

  4. Rabīʿ II (Rabīʿ ath-Thānī ربيع الثاني or Rabīʿ al-Ākhir ربيع الآخ

..................... ............ so on SEE

Thus , since there is no attribute save month's name , it is expwcted to have a method retrieve this info ?

What's this method?

Padre answered 25/11, 2014 at 7:31 Comment(0)
H
9

The date does not contain information about the names of the months or days. To get that you need a formatter:

System.out.println(DateTimeFormatter.ofPattern("MMMM").format(hd));

prints Safar.

Hellkite answered 25/11, 2014 at 8:58 Comment(3)
what to do if we want to show Safar 14-1444Daph
Change the pattern to get the format you need. See: docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/…Hellkite
appreciate your response. Above reference help me to do so DateTimeFormatter.ofPattern("MMMM-dd-yyyy").format(hidate)Daph
P
4

Since the main language of UmalQura is the arabic langugage, Developers & programmers who uses UmalQuraCalender want to display the month in arabic. Thus , we base on @assylias answer we can add the Locale object to print صفر instead of Safar

System.out.println(DateTimeFormatter.ofPattern("MMMM").format(hd,new Locale("ar")));
Padre answered 26/11, 2014 at 5:9 Comment(0)
S
1
public String getIslamicDate(){
    return  DateTimeFormatter.ofPattern("MMMM",new Locale("ar")).format(HijrahDate.now());
}

I think this should work just fine and return the month in arabic language

Swagsman answered 17/10, 2018 at 19:27 Comment(1)
but, this way date and year not comes in Arabic, is there any way ?Auramine

© 2022 - 2024 — McMap. All rights reserved.