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

Android Joda DateTime one hour off

I have a TimePickerDialog which lets the user pick a time. The TimePickerDialog has a onTimeSet method that gets called when the user finished picking the time. I pass the arguments to a second method, setTime(int hour, int minute) which saves the…
mo5ch
  • 138
  • 1
  • 10
1
vote
2 answers

Converting Date string with offset to custom format ignoring the offset

I have an input date string with an offset which I want to convert to a custom format. The problem is, when I do the conversion using Joda DateTimeFormatter, the resulting string is in my local timezone. How do I convert the string, but leave the…
drunkenfist
  • 2,958
  • 12
  • 39
  • 73
1
vote
2 answers

how to get current time from given timezone name in java?

I want to get current time from given timezone that can be like "IST" or "Indian Standard Time" etc. I am not able get time when input is "Indian Standard Time" or "Coordinated Universal Time". it works only for "IST" or "UTC" or "EST" etc. i have…
Deepak Pareek
  • 39
  • 1
  • 8
1
vote
1 answer

Jodatime overlap method not checking equals

For finding the overlap of two date ranges i understand we need something like. (thisStart <= otherEnd ) && (otherStart <= thisEnd) But inside the overlaps method from Joda Time I see thisStart < otherEnd && otherStart < thisEnd This wont cover…
RBz
  • 896
  • 3
  • 17
  • 34
1
vote
1 answer

ElasticSearch indexing issue ,failed to parse timestamp

i am new to ELK . i have created index in Elasticsearch { "logstash": { "aliases": {}, "mappings": { "log": { "dynamic_templates": [ { "message_field": { "path_match": "message", …
niting
  • 55
  • 4
  • 12
1
vote
1 answer

DateTime API produces different result based on the code execution time

I am trying to create a fixed date time using joda DateTime, surprisingly different results are produced based on the code execution time(current system time). Here is the code DateTimeZone.setDefault(DateTimeZone.forID("Europe/Brussels")); …
null
  • 548
  • 3
  • 14
1
vote
1 answer

Generic bounds with pre-generics raw types

I've got a Collection with the element type of > because it's ordered. I'm trying to use Joda LocalTime with this collection - e.g. MyCollection. Unfortunately, apparently Joda is pre-generics; LocalTime…
Steven Schlansker
  • 37,580
  • 14
  • 81
  • 100
1
vote
0 answers

Joda-time library: issue in Json schema validation

I am trying to implement json schema validation for my web application using joda-time lib. Current weblogic version is 10.3.6. Please find the weblogic .xml entry for the same:
Rashmi Ranjan mallick
  • 6,390
  • 8
  • 42
  • 59
1
vote
1 answer

list days in the week, given week and year

Using joda-time, is it possible to get the list of dates in a particular week, given only week and year? All the examples that I found, I need to set a date (with day-month-year), only then I can find the list of dates in a given week.
imin
  • 4,504
  • 13
  • 56
  • 103
1
vote
3 answers

How to format Joda Time to dd-mm-yyyy in android?

String DOB = new DateTime(Long.parseLong(dob) * 1000, DateTimeZone.UTC ).toString(); // Current // YYYY-MM-DD // DOB = "1994-05-10T00:00.000Z" // Required // DD-MM-YYYY // DOB = "10-05-1994" I want to remove the hh:mm:ss and format the…
Sadda Hussain
  • 343
  • 5
  • 19
1
vote
1 answer

Persisting time ojects as entities instead of value types?

I'm using Joda Time DateTime to handle date and time. I persist objects of this kind using the class PersistentDateTime bundled in the jodatime hibernate code. I have large collections of DateTime objects, and I currently persist them in the…
cdarwin
  • 4,141
  • 9
  • 42
  • 66
1
vote
3 answers

Oracle Timestamp to BST time conversion

I know that there are tons of different tutorials on time conversion, but this one got me very confused. My task is to read UTC DATE from Oracle DB and convert it into BST time (in a more human readable format). Facts: Field in the DB is of DATE…
amerykanin
  • 255
  • 2
  • 5
  • 15
1
vote
1 answer

joda datetime with timezone offset, after insert to DB will change to UTC time

I am using jodatime now, but I got one issue recently, which is: when I get a joda time (it always with timezone offset), say 2017-01-31T00:00:00.000+08:00, after I insert this value to database (I am using Hibernate4 as my ORM framework), the value…
Koenigsegg
  • 575
  • 1
  • 9
  • 23
1
vote
1 answer

Jackson JavaTimeModule for Joda Time?

I would like to set global Jackson serialization setting for Local Date and use something like JavaTimeModule for java.time but for JodaTime's Local Date. Does something like JavaTimeModule exist for Joda Time?
jnemecz
  • 3,171
  • 8
  • 41
  • 77
1
vote
2 answers

Joda DateTime Invalid format

I'm trying to get the current DateTime with my DateTimeFormat pattern, but i'm getting the exception... //sets the current date DateTime currentDate = new DateTime(); DateTimeFormatter dtf = DateTimeFormat.forPattern("dd/MM/YYYY…
MarioC
  • 2,934
  • 15
  • 59
  • 111