JavaLunarCore is the core library of Lunar calendar in Android devices. The library does not contain any UI implementation only Lunar date conversion and Good/Bad/Normal day calculation in file LunarCoreHelper.java.
This library is used in Lịch Như Ý by Appota. The app was in Top 10 - Productivity on Google Play multiple times.
Add JitPack repository in your project's build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency in your app's build.gradle
The latestVersion
is
dependencies {
implementation 'com.github.appota:JavaLunarCore:${latestVersion}'
}
Convert between the Gregorian Calendar (or the Western Solar Calendar) and the Lunar Calendar (or the Traditional Chinese/Vietnamese Calendar)
int[] lunarDay = LunarCoreHelper.convertSolar2Lunar(day, month, year, timeZone);
Log.d(TAG, "Lunar date:\n" +
"Day: " + lunarDay[0] + "\n" +
"Month: " + lunarDay[1] + "\n" +
"Year: " + lunarDay[2] + "\n" +
"Leap Month: " + (lunarDay[3]==1 ? "Yes" : "No"));
int[] solarDay = LunarCoreHelper.convertLunar2Solar(day, month, year, lunarLeapMonth, timeZone);
Log.d(TAG, "Solar date:\n" +
"Day: " + solarDay[0] + "\n" +
"Month: " + solarDay[1] + "\n" +
"Year: " + solarDay[2] + "\n");
Get Can-Chi (Stem-Branch) of a day based on Sexagenary cycle
Log.d(TAG, "Can Chi: " + LunarCoreHelper.getCanDayLunar(solarDay, solarMonth, solarYear) + " "
+ LunarCoreHelper.getChiDayLunar(solarDay, solarMonth, solarYear) + "\n" +
"Chinese 干支: " + LunarCoreHelper.getChineseCanDayLunar(solarDay, solarMonth, solarYear)
+ LunarCoreHelper.getChineseChiDayLunar(solarDay, solarMonth, solarYear));
Get day rating (Good/Bad/Normal Day)
String chiDay = LunarCoreHelper.getChiDayLunar(solarDay, solarMonth, solarYear);
Log.d(TAG, "Good/Bad Day: " + LunarCoreHelper.rateDay(chiDay, lunarMonth));