Danny
Danny

Reputation: 117

Setting DateTime to Certain Value

I am using joda time to compare an array of dates. My goal is to go through the array and see what dates are missing. I plan on accomplishing this by assigning the first variable in the array to a DateTime variable, then counting up the array and Date Time. If the DateTime equals array[x], then both the DateTime and the array will increment by one. If the DateTime does not equal the array (meaning that a date is missing) the DateTime will increment by one and print out the date until DateTime equals Array[x]. At the moment though, I am just trying to get it so that the first date (at holder[2]) is the value of DateTime firstDate.

My question is how do I make it so that I can assign holder[2] to DateTime firstDate? Simply assigning firstDate to holder[2] is returning an error.

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

}

Important things about my code:

  1. I am using a BufferedReader to take information in from a very large file (20gb) so I am reading in from the text file line by line (and for each line holder[2] is the date)

  2. The format of the Date on the text file is in yyyymmdd and I want to compare the string of that to the string of DateTime (thus the first thing I need to do is assign the first value of the array to DateTime which just happens to be my question).

  3. I have correctly setup Joda Time

Upvotes: 0

Views: 99

Answers (1)

MaQy
MaQy

Reputation: 476

If what you have in holder[2] is a string representation of a date with format "yyyyMMDD", then you need to use the formatter you defined:

firstDate = dtf.parseDateTime(holder[2]);

Upvotes: 1

Related Questions