Reputation: 3674
android.text.format.Time has a method called getJulianDay that returns the day number since epoch. But docs says that:
This class was deprecated in API level 22. Use GregorianCalendar instead.
Is there any method in GregorianCalendar
that does the same work?
Upvotes: 3
Views: 2401
Reputation: 21
En Kotlin, para fechas actuales, o posteriores a 1970:
/**
* 1970-01-01T00:00 Astronomical Julian Day= 2_440_587.5
* @param fechaZulu
* @return Astronomical Julian Day
*/
fun DJdiasJulianosAstromicos(fechaZulu: Calendar): Double {
return 2_440_587.5 + fechaZulu.timeInMillis / 86_400_000.0 //=(1000 * 60 * 60 * 24.0)
}
Upvotes: 1
Reputation: 21710
AFIK there is not, but maybe this can help, fractional parts are ignored.
public static int getJulianDay(Calendar cal) {
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH)+1; //Note January returns 0
int date = cal.get(Calendar.DATE);
return (1461 * (year + 4800 + (month - 14) / 12)) / 4
+ (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12
- (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 + date - 32075;
}
The formula for the calculation is from https://en.wikipedia.org/wiki/Julian_day see section "Converting Gregorian calendar date to Julian Day Number"
Upvotes: 6