Cem
Cem

Reputation: 57

Trying to find the difference in days with JodaTime

Simply, I'm storing an 'initial date' data as a String variable in a text file e.g. 02-02-2015, and I just need to know if 3 days has passed from that initial date. I've been recommended to use JodaTime but I kept on recieving errors with it which I'm presuming is because I'm comparing String and Int variables.

Is this possible, if so how? Thanks in advance?

EDIT: Apologies I didn't post the code.

public void startDelay() {
     DateTime dt = new DateTime();
     DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
     delayPin = fmt.print(dt);
}

public int delayEnded() {
     DateTime dt = new DateTime();
     DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
     String today = fmt.print(dt);
     delayProgress = Days.daysBetween(new DateTime(delayPin), new DateTime(today)).getDays();
     return delayProgress;
}

delayPin is being stored in the text file. I repeated the method to get todays date within the second delayEnded method.

Upvotes: 0

Views: 42

Answers (1)

Vladimir
Vladimir

Reputation: 76

Something like this?

String storedDateString = "02-02-2015";
DateTimeFormatter format =
            new DateTimeFormatterBuilder().appendPattern("MM-dd-yyyy").toFormatter();
Boolean isThreeDaysPassed =
            LocalDate.now().minusDays(3).isAfter(LocalDate.parse(storedDateString, format));

Upvotes: 2

Related Questions