Danny
Danny

Reputation: 117

Random Number Change With Joda Time

My Joda Time is changing a number from 9 to 1 in my code.

Code:

String name = getFileName();
BufferedReader reader = new BufferedReader(new FileReader(name));

DateTime firstDate = new DateTime();
DateTimeFormatter dtf = DateTimeFormat.forPattern("YYYYMMDD");
String date = dtf.print(firstDate);
System.out.println(date);

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

    firstDate = dtf.parseDateTime(holder[2]);
    System.out.println(holder[2]);
    System.out.println(firstDate);
    String useFirstDate = dtf.print(firstDate);
    System.out.println(useFirstDate);
    System.out.println("here");
    break;
}

Output:

Please input File Name
futuresmin
201306172 //System.out.println(date);
19870901  //System.out.println(holder[2]);
1987-01-01T00:00:00.000-05:00 //System.out.println(firstDate);
19870101  //System.out.println(useFirstDate);
here  //System.out.println("here");

I do not know if this is a common issue, or if it is just me, yet I have not found anything on the internet regarding this issue. Why would Joda Time change 19870901 to 19870101?

Upvotes: 0

Views: 71

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

"DD" is day of year, not day of month, which is "dd". Your format string is incorrect.


On an unrelated note, it's difficult to correlate your output with your code. In general, it's best to keep the noise to a minimum, and make it explicit which output line comes from which code, like with a header.

Upvotes: 3

Related Questions