2015-08-23 32 views
0

雖然提到我碰到下面的代碼來獲取當天某一課程:儒略日VS Date對象得到了本日

int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); 
long dateTime; 
dateTime = dayTime.setJulianDay(julianStartDay); 
day = getReadableDateString(dateTime); 

    private String getReadableDateString(long time){ 
      SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("E MMM d"); 
      return shortenedDateFormat.format(time); 
     } 

我的疑問是,爲什麼我們使用這個朱利安方法來代替只是直接從Date類對象中提取當天的日期和時間。

+0

兩個問題:1.你問爲什麼你的例子使用'getJulianDay()'而不是直接使用'System.currentTimeMilis()'?和2.這個特殊的例子有多大? – ricky3350

+0

1.是的,也無法直接使用Date類對象來獲取當前日期? 2.關於故鄉,我不知道,但我猜它在2012年之後...... – ghostrider

+0

上面的代碼似乎做了兩件事:(1)將變量dayTime的值更改爲今天午夜,原始時區,以及(2)將'day'設置爲表示今天的字符串。你如何打算用'Date'做第一部分? – RealSkeptic

回答

2

您的申請與東正教的宗教日曆有關嗎?據我所知,這是Julian calendar仍在使用的唯一位置。

Java DateCalendar默認使用Gregorian calendar。 (Calendar.getInstance方法返回一個GregorianCalendar對象,除非指定了兩個特定語言環境中的一個)。如果您的應用程序需要使用Julian日曆,那麼這將解釋此實現。