Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Gregorian date to Julian date with the Java 8 Date/Time API?

I have a date in the Gregorian calendar and want to look up the same day in the Julian calendar.

This should be easy with the Date/Time API of Java 8 but I couldn't find a way to do it. The code should look something like this:

/*
 * LocalDate uses the Gregorian calendar
 */
LocalDate date = LocalDate.parse("2017-10-29");


/*
 * switch from Gregorian calendar to Julian calendar here
 */
;


/*
 * output should be 2017-10-16
 */
System.out.println(date);

You can try it out online here


Edit

This is certainly no duplicate of Convert from Gregorian to Julian calendar. My question asks specifically about the Java Data/Time API.

like image 971
Paule Avatar asked Oct 29 '17 14:10

Paule


1 Answers

The Julian chronology is not built into Java 8 or 9. Instead, the ThreeTen-Extra project has JulianChronology and JulianDate classes. Using it is simple.

JulianDate jd = JulianDate.from(localIsoDate);
like image 60
JodaStephen Avatar answered Sep 23 '22 15:09

JodaStephen