Questions tagged [jodatime]

Joda-Time provides a quality replacement for the Java date and time classes. The design allows for multiple calendar systems, while still providing a simple API.

Joda-Time is a library which can be used as a replacement for the Java date and time classes. From Java SE 8 onwards, users are asked to migrate to java.time (JSR-310).

Sample Code

This sample is provided from code written as part of an interval type enum which could calculate a series of dates at that interval. It provides a great example of what it looks like to call some common methods on Joda's DateTime object.

public DateTime getNextDate(DateTime dt, int interval) {
    switch(this) {
    case SECOND:
        return dt.plusSeconds(interval);
    case MINUTE:
        return dt.plusMinutes(interval);
    case HOUR:
        return dt.plusHours(interval);
    case DAY:
        return dt.plusDays(interval);
    case WEEK:
        dt = dt.plusDays(3).plusWeeks(interval - 1);
        return dt.withDayOfWeek(6);
    case MONTH:
        dt = dt.plusDays(3).plusMonths(interval - 1);
        return dt.withDayOfMonth(dt.dayOfMonth().getMaximumValue());
    case QUARTER:
        dt = dt.plusDays(3).plusMonths((interval - 1) * 3);
        dt = dt.plusMonths((3 - (dt.getMonthOfYear() % 3)) % 3);
        return dt.withDayOfMonth(dt.dayOfMonth().getMaximumValue());
    case YEAR:
        dt = dt.plusDays(3).plusYears(interval - 1);
        return dt.withDayOfYear(dt.dayOfYear().getMaximumValue());
    }
    return dt;
}

Some helpful SO posts

Useful Links

2931 questions
1
vote
2 answers

formatting the org.joda.time.LocalDate

I am working on java application. I am converting List of LocalDates to String array. When I print the String array I should get the formatted date. Current date format is 2016-10-12, 2016-10-13.. I want to format it to October 12,2016 October…
joan
  • 131
  • 2
  • 4
  • 12
1
vote
1 answer

Trying to find time difference in Joda Time between 2 DateTime objects

I'm trying to find the difference between 2 times using Joda Time. I've tried using some of the examples on here and can not get a value to return. Here is what I've tried: Where time is in a format like 17:23 and the to and from variables are…
Wayne Johnson
  • 214
  • 3
  • 18
1
vote
0 answers

Joda dateTime Exception

We are getting this exception only with componentTests (service tests). > com.thoughtworks.xstream.converters.ConversionException: Cannot create > org.joda.time.chrono.ISOChronology$Stub by JDK serialization : null : > Cannot create…
user2868864
  • 165
  • 2
  • 12
1
vote
4 answers

Joda time calculating the days, hours, minutes, and seconds between two datetime objects

I am trying to find the days, hours, minutes and seconds between two date/times. I thought I could use period and I tried the code below but I get a non nonsensical answer. DateTime dt1 = new DateTime("2004-12-13T21:39:45.618-06:00"); …
Nicholas Muir
  • 2,897
  • 8
  • 39
  • 89
1
vote
1 answer

Groovy way to find dates in range by the day of the week

What would be the Groovy way to accomplish Joda Time example below: LocalDate startDate = new LocalDate(2016, 11, 8); LocalDate endDate = new LocalDate(2017, 5, 1); LocalDate thisMonday = startDate.withDayOfWeek(DateTimeConstants.MONDAY); if…
Micor
  • 1,502
  • 4
  • 20
  • 39
1
vote
1 answer

Getting a list of dates between two dates in java different results

For some reasons using plusDays(1) doesnt give me the correct answer. It increments the results instead by 1. What to change to make this code below work properly. Removing plusDays(1) doesnt seem to work. What am i doing wrong here. It should…
Nb12se
  • 513
  • 6
  • 21
1
vote
2 answers

Get months between two dates ignoring the days

I want to count the months between two dates, and only compare with their months while ignoring the days, so 2012-01-31 and 2012-02-01 should have 1 month difference between them. I do this with joda-time: import org.joda.time.*; PeriodType…
Freewind
  • 193,756
  • 157
  • 432
  • 708
1
vote
3 answers

How to calculate number of event occurrences with Joda Time?

Given an example event recurrence schedule which is defined as follows: StartTime: Monday, 2016-June-06 09:00H EndTime: Monday, 2016-August-29 10:00H Period: Bi-weekly This means, every 2 weeks on Monday at 09:00H, until 29th August 2016.…
codinguser
  • 5,562
  • 2
  • 33
  • 40
1
vote
1 answer

Consider end date also for days calculation logic in java

For calculating days between two dates(Date or Calendar object) consider the end date also for calculation. I used below method: public static int daysBetween(Date d1, Date d2) {  return Days.daysBetween( new LocalDate(d1.getTime()), new…
pandiaraj
  • 580
  • 1
  • 6
  • 18
1
vote
1 answer

How to set a fixed date with JodaTime?

I'm looking for any way to create a fixed day to month using JodaTime. I have a JSpinner to set integer values and I want get this value and create the Date. For example: JSpinner has 15, I want to create the date 2016-09-15, 2016-10-15, 2016-11-15.…
FernandoPaiva
  • 4,410
  • 13
  • 59
  • 118
1
vote
2 answers

A Bug in Jodatime calculating Period between 2 date range (which is ALMOST a year)

I just started to use Joda Time and for a week now I was satisfied with the results. I am trying to get the time range period between two dates of the format 'yyyy-MM-dd HH'. Until I came to a test case I am writing and it seems to me the result…
Rodel
  • 147
  • 1
  • 6
1
vote
2 answers

Disable Button on CardView android

I am having trouble in setting the Button to invisible on a CardView after particular time What i am trying to achieve: I have a CardView with a Button. When user places an order, order date & time is stored in MySQL server DB. I get this time from…
Sriram
  • 449
  • 3
  • 8
  • 15
1
vote
1 answer

Grails 2.4 joda-time plugin

I am trying to add JodaTime plugin into my Grails application but it's giving error. I added plugins into BuildConfig like plugins { compile ":joda-time:1.9" } After downloading it's giving error.
Ranjan
  • 929
  • 1
  • 6
  • 19
1
vote
3 answers

month difference between two dates in Scala

I have two dates in Scala of format 'yyyy-MM-dd' and they both are the last day of a month (2015-05-31) and I want to find the month difference between then. I have the following code but it is not straighforward to find the month difference. val…
HHH
  • 6,085
  • 20
  • 92
  • 164
1
vote
1 answer

Current Joda Time performance on Android?

I've heard performance concerns in the past about using Joda Time on Android. One specific example was an issue with the way that timezone data was loaded, which was causing a considerable amount of memory to remain allocated when it was no longer…
spaaarky21
  • 6,524
  • 7
  • 52
  • 65
1 2 3
99
100