2013-06-21 49 views
0

我正在使用joda時間來比較日期數組。我的目標是通過數組來看看錯過了哪些日期。我計劃通過將數組中的第一個變量賦值給DateTime變量,然後對數組和數字進行計數來完成此操作。如果DateTime等於array[x],那麼DateTime和數組都將遞增1。如果DateTime與陣列不相等(意思是缺少日期)DateTime將遞增1並打印日期,直到DateTime等於Array[x]。目前,我只是試圖弄清楚,以便第一次約會(持有者[2])的價值爲DateTime firstDate將DateTime設置爲某個值

我的問題是我該如何製作,以便我可以將holder[2]分配到DateTime firstDate?簡單地將firstDate分配給holder[2]即返回錯誤。

DateTime firstDate = new DateTime(); 
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMDD"); 
String date = dtf.print(firstDate); 

String fake; 

while ((fake = reader.readLine()) != null) { 
    String [] holder = fake.split(" "); 

    firstDate = holder[2]; //******the issue****** 
    System.out.println(firstdate); 

} 

我的代碼的重要事情:

  1. 我使用的是BufferedReader採取從一個非常大的文件(20GB)的信息,所以我從文本文件中逐行讀取(和每行holder[2]是日期)

  2. 上的文本文件中的日期格式是年月日,我想的是,字符串比較的DateTime字符串(因此我需要做的第一件事是分配fi數組的第一個值爲DateTime,這恰好是我的問題)。

  3. 我已經正確安裝約達時間

+0

您的格式只包含年份,月份和日期。你爲什麼不使用'LocalDate'? –

回答

1

如果您有holder[2]什麼是日期與格式「年月日」,那麼你需要使用你所定義的格式字符串表示:

firstDate = dtf.parseDateTime(holder[2]); 
相關問題