I am working on a project in Java and I need to change different types of dates to each other like (Gregorian to Chinese and vice versa and Gregorian to Hijri and vice versa). I try to use Time4j which has this facility to convert different types of dates to each other but unfortunately, I didn't understand how to work with this library even after I tried to read its documentation.
Right now I am trying to convert Gregorian date to Chinese date but I can't get the normal year in Chinese date when I use object.getYear()
it returns cyclic year but I need normal year like 2019.
This is my code:
import net.time4j.PlainDate;
import net.time4j.calendar.ChineseCalendar;
public class DateConverter {
static PlainDate gregorian = PlainDate.nowInSystemTime();
static ChineseCalendar obj = gregorian.transform(ChineseCalendar.axis());
public static void main(String[] args) {
String result = obj.getMonth() + "/" + obj.getDayOfMonth() + "/" + obj.getYear() ;
System.out.println(result); // 8/30/ji-hai(36)
System.out.println(obj); // chinese[ji-hai(2019)-8-30]
}
}
I need this type of year ji-hai(2019) and it is in default toString()
method and when I use object.getYear()
method it returns ji-hai(36).
Now how can I change my return value from ji-hai(36) to ji-hai(2019). Also if I want to receive the Gregorian date from a user how should I prepared for this conversion? Can I receive it as a String text and cast it to Gregorian date and then use it? Is is possible?
Also if you know a good resource that explains the usage of classes and methods of Time4j with example please share it with me.
thank you.