2016-09-30 27 views
0

Timeクラスは非推奨であるため、次の関数ではgetJulianDay()を使用できなくなりました。私はそれを達成するためにCalenderまたはGregorianCalenderクラスを使いたい。私は[質問]から私の答えを部分的に得ました:Time getJulianDay() deprecated which alternatives to convert date to julian and vice versa? 私はそのようなクラスには新しく、GregorianCalenderをどのようにして長時間変換して関数に戻すことができないのか分かりません。ユリウス暦の日付を取得するにはどうすればいいですか?ありがとう!Time.getJulianDay()は推奨されていません。どのコードが代わりに作業を行うのですか?

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

ユリウス暦の日付について[多くの質問と回答があります(/検索?q =%5Bjava%5D +ジュリアン+日付)です。彼らはどうしたらいいですか?たとえば、[this one](http://stackoverflow.com/questions/20035403/julian-date-to- regular-date-conversion)? –

答えて

0

これは必要なものですか?

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(); 
} 
関連する問題