Sample Julian Dates:
2009218
2009225
2009243
如何將它們轉換爲正常日期?朱利安日期轉換
我嘗試使用online converter將他們和我的GOT
12-13-7359爲2009225!沒有意義!
Sample Julian Dates:
2009218
2009225
2009243
如何將它們轉換爲正常日期?朱利安日期轉換
我嘗試使用online converter將他們和我的GOT
12-13-7359爲2009225!沒有意義!
使用Joda-Time庫,做這樣的事情:
String dateStr = "2009218";
MutableDateTime mdt = new MutableDateTime();
mdt.setYear(Integer.parseInt(dateStr.subString(0,3)));
mdt.setDayOfYear(Integer.parseInt(dateStr.subString(4)));
Date parsedDate = mdt.toDate();
使用Java API:
String dateStr = "2009218";
Calendar cal = new GregorianCalendar();
cal.set(Calendar.YEAR,Integer.parseInt(dateStr.subString(0,3)));
cal.set(Calendar.DAY_OF_YEAR,Integer.parseInt(dateStr.subString(4)));
Date parsedDate = cal.getTime();
---- ----編輯感謝 亞歷克斯提供最佳回答:
Date myDate = new SimpleDateFormat("yyyyD").parse("2009218")
這個月怎麼樣? – 2010-06-14 11:59:31
MutableDateTime會計算出該月份,因爲它知道年份和年份。 – 2010-06-14 12:05:02
有沒有辦法可以使用Java API來做到這一點? – 2010-06-14 12:06:29
另一種格式是CYYDDDD我寫了這個函數Java
public static int convertToJulian(Date date){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
String syear = String.format("%04d",year).substring(2);
int century = Integer.parseInt(String.valueOf(((year/100)+1)).substring(1));
int julian = Integer.parseInt(String.format("%d%s%03d",century,syear,calendar.get(Calendar.DAY_OF_YEAR)));
return julian;
}
你的例子不是朱利安日期。朱利安日期是公元前4713年1月1日以來的天數 - 例如2000-01-01爲2.451.545。 (如果2009225是你想要的朱利安日期,在線轉換器是正確的) – oezi 2010-06-14 11:29:07
我這麼認爲,但我不知道那些日期是那種日期!甚至不能問。 – 2010-06-14 11:30:09
目前還不清楚你想要轉換的東西:Julian日曆日期?或修改過的朱利安_Days_(天文數據),如你的鏈接?如果這些日期是從一年開始的,那麼存在模棱兩可的餘地(2009年1月11日或11月1日?)。 – McDowell 2010-06-14 11:59:57