Time.getJulianDay() 已弃用。哪个代码可以代替完成工作?

Time.getJulianDay() deprecated. Which code would get the work done instead?

由于时间 class 已弃用,我无法再在以下函数中使用 getJulianDay()。我想使用 Calender 或 GregorianCalender class 来实现相同的目的。我从[问题]得到了部分答案: 但我对这种 classes 很陌生,所以我不知道如何将 GregorianCalender 转换为 long 以便我可以在函数中 return 它。我怎样才能得到儒略日期?谢谢!

public static long normalizeDate(long startDate) {
    // normalize the start date to the beginning of the (UTC) day
    Time time = new Time();
    time.set(startDate);
    int julianDay = Time.getJulianDay(startDate, time.gmtoff);
    return time.setJulianDay(julianDay);
}

这符合您的需求吗?

public static long normalizeDate(long startDate) {
    // normalize the start date to the beginning of the (UTC) day
    GregorianCalendar date = (GregorianCalendar)     GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC"));
    date.setTime(new Date(startDate));
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);

    //transform your calendar to a long in the way you prefer
    return date.getTimeInMillis();
}