Time getJulianDay() 弃用了哪些替代方法可以将日期转换为 julian,反之亦然?

Time getJulianDay() deprecated which alternatives to convert date to julian and vice versa?

我想使用 GregorianCalendar 而不是时间 class,android 文档如何建议,但如何管理儒略日以将日期作为 int 存储在我的 sqlLite 数据库中?

如何转换此代码?

   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);
}

当我查询一行时,如何才能得到儒略日之前的正常日期?

如果您只是需要将日期转换为整数以保存在数据库中,您可以使用 SimpleDateFormatter 将日期转换为字符串,然后将字符串转换为整数。类似于:

Date date = new Date(startDate);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
String dateString = formatter.format(date);
int dateInt = Integer.parseInt(dateString);

这将创建一个整数,您可以轻松地在数据库中保存和检索。

您应该使用类似于以下的代码:

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
}