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
1 answer

Parsing redundant information with Joda Time

I am dealing with strings such as the following: 0022 GMT (0822 HKT) July 21, 2016 Obviously these strings specify the time of the day twice for two different time zones. Can the pattern syntax of Joda Time's DateTimeFormat.forPattern() handle this…
zepp133
  • 1,542
  • 2
  • 19
  • 23
1
vote
3 answers

Find if hours ranges overlap regardless of the date

I have a set of two hours ranges 10 PM - 02 AM 01 AM - 08 AM I want to check if any of them over lap regardless of the the date. For Example: The first range could be on 1st and 2nd of Aug while the second range could be 10th of Aug. This is what I…
Matto
  • 2,538
  • 2
  • 18
  • 23
1
vote
0 answers

Excel DAYS360 implementation using joda time DateTime

How can I implement Excel DAYS360 function in java using Joda Time API ? It seems apache POI has one Days360 implementation but I am not using apache POI.
Ritesh
  • 113
  • 8
1
vote
1 answer

Getting Time Zone from Time Zone offset?

Is there an option in JodaTime, where once a ISO valid string is parsed with time zone offset, I can get back the time zone? String dateTime = "2012-11-29T23:08:56.23-04:00" where -04:00 is the time zone offset Once this is parsed, is there any…
Gowrav
  • 289
  • 1
  • 4
  • 20
1
vote
1 answer

Why does joda time update the time and offset when java time doesn't?

I can't seem to figure out why joda time is updating the time and offset hours after daylight saving time, but java time doesn't. DateTime dateTime = new DateTime("2016-04-05T10:06:21.636-05:00").withDayOfWeek(5); TemporalField dayOfWeek =…
Jon
  • 453
  • 5
  • 18
1
vote
1 answer

Why is withWeekOfWeekyear giving me a different offset?

I'm trying to convert withWeekOfWeekyear over to java.time. I can't seem to figure out why I'm getting a different offset with withWeekOfWeekyear compared to weekOfWeekBasedYear. DateTime dateTimeWeek = new DateTime().withWeekOfWeekyear(1); …
Jon
  • 453
  • 5
  • 18
1
vote
1 answer

Why does parsing a date with weekyear return the wrong year?

DateTime time=DateTimeFormat.forPattern("yyyy-ww").parseDateTime("2013-01"); where DateTimeFormat is org.joda.time.format.DateTimeFormat. When I execute the above, time becomes 2013-12-30T00:00:00.000 what am I doing wrong? Is this a bug? I expect…
Tony Wolff
  • 732
  • 1
  • 10
  • 23
1
vote
0 answers

Android JodaTime - "Invalid Format" crash with parseDateTime 3-char month

We have an app that is hooked up to Fabric/Crashltyics. One of our top reported crashes is being triggered on the following lines of code: DateTimeFormatter mMonthPattern =…
svguerin3
  • 2,433
  • 3
  • 29
  • 53
1
vote
2 answers

Configuration of CustomJacksonMapper to deal with DateTime is not working on Spring 4.1.5

Here are the configurations that I've made: My config file:
Gabriel
  • 952
  • 10
  • 31
1
vote
1 answer

Similar solutions for java.lang.NoClassDefFoundError: org/joda/time/DateTime not working

I have seen this question posted here before and I have looked at the solutions however I cannot fix the problem I'm having. I created a very simple Maven project in Eclipse for Java and I want to run the output jar file e.g. java -jar…
TKPhillyBurb
  • 91
  • 3
  • 11
1
vote
3 answers

Convert a string into iso date format

So I am trying to convert a string into an iso format for the date. This is the string that I am trying to convert "2016-07-05 02:14:35.0" I would like to have it in this format the iso 8601 "2016-07-05T02:14:35.0" I have this so far …
MNM
  • 2,673
  • 6
  • 38
  • 73
1
vote
1 answer

Joda Time getSecondOfDay on DST switch day

I'm getting strange behavior from Joda Time when trying to get the seconds since midnight on a DST switch day. My code: public static void main(String[] args) { DateTimeZone timeZone = DateTimeZone.getDefault(); …
Martin Geisse
  • 1,189
  • 1
  • 9
  • 22
1
vote
1 answer

What is the easiest way to print a DateTime using an hour adjustment instead of a locale?

I am working on a system where each user can specify a setting of their adjustment from UTC in hours. So when a date/time is input from this user, the value is adjusted by their setting and saved as UTC. Similarly, on the way out, the date/time is…
David Spence
  • 7,999
  • 3
  • 39
  • 63
1
vote
0 answers

Convert the following jsonElement to joda DateTime using custom deserializer

I have a JsonElement {"iMillis":1465936837501,"iChronology":{"iBase":{"iMinDaysInFirstWeek":4}}}. I want to deserialize it to joda DateTime. I am trying to use custom deserializer: class DateTimeDeserializer implements JsonDeserializer { …
1
vote
2 answers

Joda time library getdays giving wrong result

public static void main(String args[]) throws ParseException{ String string = "May 2, 2016"; DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH); Date date = format.parse(string); System.out.println(date); …
ManMohan Vyas
  • 4,004
  • 4
  • 27
  • 40
1 2 3
99
100