jodatime « Date Time « Java Data Type Q&A

1. Are there any cons to using jodatime?

I want to convince the architecture manager to include the joda time jar in our product. Do you know any disadvantages in using it? I think joda time needs to be constantly updated ...

2. Should I use Java date and time classes or go with a 3rd party library like Joda Time?

I'm creating a web based system which will be used in countries from all over the world. One type of data which must be stored is dates and times. What are the ...

3. DateTime is within in interval in JodaTime

Is there a API method in JodaTime to see whether a DateTime is within [start, end], i.e. the boundary is included? Only thing I found was new Interval(start, end).contains(dateTime) but this seems ...

4. Joda-Time: Period to string

I'm using the Joda-Time library with Java. I'm having some difficulty trying to turn a Period object to a string in the format of "x days, x hours, x ...

5. Joda Time bug or my mistake? (Java Joda Time dates as strings parsing)

so I was having a problem parsing a date, using the JodaTime chronology IslamicChronology so wrote a small example to demonstrate my problem. Here's the code:

import org.joda.time.Chronology;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.chrono.IslamicChronology;

import java.util.Date;

 * ...

6. Joda-Time: How to get the next friday?

How can I get the next friday with the Joda-Time API. The LocalDate of today is today. It looks to me you have to decide whever you are before or after the ...

7. Jodatime : what is there to keep up to date?

I read (dont't know where anymore, but see here) when using Jodatime you have to keep files up to date. What kind of files? Why is that?

8. Joda Time to be included in Java 7?

I've read rumors that Joda Time is slated to be included in Java 7, but am having trouble locating a definitive source for this information. Will Joda Time be included in ...

9. javadoc for ISODateTimeFormat.dateTime()

The javadoc for org.joda.time.format.ISODateTimeFormat.dateTime() is:

Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ). The time zone offset is 'Z' for zero, ...

10. Can I parse relative times with JodaTime?

I'd love to be able to parse relative strings like now and yesterday and get JodaTime DateTimes. Is it possible? DateTimeFormat.forPattern and doesn't seem to support English relative times and I ...

11. The API Joda-Time(java) doesnt respect the ISO 8601: bug or feature?

According to their website, the class DUration implements the ISO 8601 But let see an example. It is a duration of 14min & 51sec. In ISO 8601 those code are equivalent ...

12. Jodatime - Custom Chronology

I would like to calculate a duration whereas 1 day will consist of 8 hours. Is creating a new Chronology is the right approach ? I did try to create a custom Chronology ...

13. Correctly defining a duration using JodaTime

I've created a method that takes two dates (in milliseconds) and returns a sentence that indicates the duration between these two dates. For the moment, I have this code:

public static String formatDuration(long ...

14. What's the best way of using joda time to manipulate monthly data?

I'm trying to work with a timeseries of monthly data. That is, there is a value for each month, and no specific date (or time) associated with it. I could have arbitrarily ...

15. How do I figure out what namespace I need to import from a java library?

I'm writing some clojure code, and I'm relying on Joda time for time handling. The problem is that I don't know what to import and the documentation isn't terribly clear ...

16. My PeriodFormatter is not behaving as I expect - what have I done wrong?

I'm having trouble using Joda Time's PeriodFormatter. I want one to report days, hours, minutes and seconds but my attempt seems to be wrapping around weeks. What should I ...

17. Odd results in Joda DateTime for 01.04.1893

My time zone is CET (Berlin).
And while testing Joda's DateTime i noticed some strange things:

new DateTime(1893, 4, 1, 0, 0, 0, 0);
=>  java.lang.IllegalArgumentException: Illegal instant due to time zone offset ...

18. Passing Joda Time objects between the App layers

I'm considering using Joda Time.
I'm wondering if I should pay attention of what type of object my Interfaces are returning.
Returning Joda Objects from my interface signature on the service layer means ...

19. Finding begin and end of year/month/day/hour

I'm using the following snipped to find the begin and end of several time periods in Joda. The little devil on my left shoulder says thats the way to go... but ...

20. Joda: what's the difference between Period, Interval and Duration?

  1. Why do we need three classes?
  2. Which one performs better?
  3. Why is dividing a Period or Duration or Interval instance not implemented? E.g. p = p.divideBy(2);

21. Joda time : How to convert String to LocalDate?

How to specify the format string to convert the date alone from string. In my case, only the date part is relevant Constructing it as DateTime fails:

String dateString = "2009-04-17";
DateTimeFormatter formatter = ...

22. Library to work with date expressions in C#?

What library can I use to calculate dates based on date expressions? A date expression would be something like:

  • "+3D" (plus three days)
  • "-1W" (minus one week)
  • "-2Y+2D+1M" (minus 2 years, plus one day, plus ...

23. check if date is within time range using joda or standart java api

I have first time as string '12:00:00' and another '19:00:00' next how to check time portion of the day is within these time values?

24. GPS Time Representation library

I am looking for a Java library that handles conversion to/from GPS Time. GPS Time has an epoch of 6 January 1980, and does not have leap seconds, ...

25. Elapsed Time with Joda

I have a DataTime field that I need to see if it's 10 years or more in the past (Think of expiring certifications). I'm new to Joda, how is that done? ...

26. Using Joda Date & Time API to parse multiple formats

I'm parsing third party log files containing date/time using Joda. The date/time is in one of two different formats, depending on the age of the log files I'm parsing. Currently I have ...

27. StackOverflowError using joda-time new Period(long)

First, sorry this is so long. I probably don't need all the code, but wanted to be sure. Second, my actual question is, am I doing something wrong, or is this a ...

28. How to convert Joda LocalDate to String in Java?

I got the answer: It's very simple.

DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/yyyy");
String formattedDate = jodeLocalDateObj.toString( fmt );

29. Bug in jodatime Period?

How come this test I wrote fails in jodatime 1.6.2? Is it a bug?

 public void testIfJodaTimePeriodsHandlesPeriodTypesOtherThanMinutesAndHours() {
  long twentyDaysInMillis = TimeUnit.MILLISECONDS.convert(20, TimeUnit.DAYS);
  Period twoWeeks = new Period(twentyDaysInMillis, PeriodType.weeks());

30. Using long timestamp or Joda Time

I have a legacy Java application, where its performance bottle neck is due to the usage of Calendar. As Calendar is a mutable object, we have to clone every-time we get ...

31. JodaTime equivalent of DateUtils.truncate()

I have never used JodaTime before, but answering this question I tried it and came up with this ugly code to unset all fields below day:

DateTime startOfMonth =

32. Clean toString from JodaTime Period

I'm calling toString() (or difference.normalizedStandard().toString()) on a Period object, and getting "PT-10H0.317S" Why is the default toString so inconvenient? What does this string even mean?

33. How to force joda time to parse only part of String?

let's assume I have following dates (in String):

I don't care about the time and zone, only date is relevant for me. So I want to try to parse it with ...

34. Joda LocalDate - still an instant?

I'm looking for a proper serializable date-only class. Got a server in Central time zone, I want users in the Eastern to enter date as 2010-11-23, and users in Pacific to ...

35. Joda time zone different than JDK's

In my client, I have this code:

System.out.println("Java tz: " + TimeZone.getDefault());
System.out.println("Joda tz: " + ISOChronology.getInstance());
These two lines run one after another. I never set time zone or user.timezone manually, just rely ...

36. LocalDate interval in Joda-time

Joda-time has an Interval class, which is a range between DateTimes. What can be used for a range of LocalDates? I want an object that represents, ...

37. Get Java Date out from Joda DateTime

I have an code like this

// old_api(Date date)
Currently, I replace Calendar with Joda DateTime. I was wondering how I can get Java Date out from Joda DateTime?

38. Joda Time: How to get dates of weekdays on some date interval?

I have two LocalDates that represent some time interval. Now i have to get LocalDates of all fridays, that this interval contains. Easiest way to do it?

39. Understanding joda time PeriodFormatter

I thought I understand it, but apparently I don't. Can you help me make these unit tests pass?

public void second() {
    assertEquals("00:00:01", OurDateTimeFormatter.format(1000));

public void minute() {

40. Approximate Time Period with Joda-Time

I am using Joda library to get time period passed since a given timestamp:

public static String getTimePassedSince(Date initialTimestamp){

        DateTime initDT = new DateTime(initialTimestamp.getTime());

41. How to convert string HH:MM to Joda Duration?

I have a field in a form to state the time duration of an event. Say, the event is to last 15 mins. So the field will have the following value: 00:15 If ...

42. Should I use threeten instead of joda-time

I came across 1) I am currently migrating Java Calendar to joda-time. I was wondering, should I use threeten instead of joda-time? Is threeten production ready? 2) Can threeten library ...

43. Why does Joda time change the PM in my input string to AM?

My input string is a PM time:

    // Sunday, January 09, 2011 6:30:00 PM
I'm using Joda Time's pattern syntax as follows to ...

44. Convert from to JodaTime

I want to convert a java.util.Date to JodaTime so as to carry out subtractions between dates. Is there a good concise way to convert from Date to JodaTime? Thanks! Kurt

45. Parsing Joda-Time Partials

I'd like to produce Partials from Strings, but can't find anything in the API that supports that. Obviously, I can write my own parser outside of the Joda-Time framework and ...

46. Does Freemarker have any integration for JodaTime?

Are there any ways to easy format Joda DateTime objects in Freemarker? For example with Java dates, we could use the ?string and other directives. I know I could call toDate ...

47. Joda Time LocalTime of 24:00 end-of-day

We're creating a scheduling application and we need to represent someone's available schedule during the day, regardless of what time zone they are in. Taking a cue from Joda Time's Interval, ...

48. Pattern to parse this string to a DateTime

Hey everyone I am trying to parse out a DateTime from a string that looks like "20110406080000.000[-4:EDT]" and am running into problems with the [-4:EDT] DateTimeFormat.forPattern("yyyyMMddHHmmss.SSS[ZZ]").parseDateTime("20110406080000.000[-4:EDT]") results in the following error

java.lang.IllegalArgumentException: ...

49. How to convert Joda LocalDate to java.util.Date?

What is the simplest way to convert a JodaTime LocalDate to java.util.Date object?

50. JodaTime get values from period

I have two DateTimes, one is the time 'since' and 'now' What I need, is get the time between then. My problem is into the format I want to get it: Example: since = '17 ...

51. need flexible datetime conversion with joda

I want to use joda to parse datetime strings in emails. Unfortunately I get all kinds of different formats, for example

Wed, 19 Jan 2011 12:52:31 -0600
Wed, 19 Jan 2011 10:15:34 -0800 ...

52. what is the direct way to copy a joda LocalTime?

I want a new instance that is a copy. I could instantiate from integers but it seems there should be a more direct way. I could also use some ...

53. Parse String by DateTimeFormatter.forPattern

I have a String:

Sun May 15 00:00:00 IST 2011
Now if I want to parse it into joda DateTime by the pattern:
EEE MMM dd 00:00:00 z yyyy
I am getting:
java.lang.IllegalArgumentException: Invalid format: "Sun ...

54. Error in Printing Period with JodaTime?

I've have a problem trying to print a given period between two dates. Let me show you the details, and then i'll put the code : Date a = May, 20th , Date ...

55. Joda DateTime not giving the expected results

Given a DateTime object at 31-March-2011 and this code:

DateTime temp1 = new DateTime(2011, 3, 31, 12, 0, 0, 0);
DateTime temp2 = temp1.plusMonths(1);
DateTime temp3 = temp2.plusMonths(1);
after the execution
temp1 = 2011-03-31T12:00:00.000+02:00
temp2 = 2011-04-30T12:00:00.000+02:00
temp3 ...

56. Problem converting java.util.Date to org.joda.time.LocalDateTime

import org.joda.time.LocalDateTime;
import java.util.Date;
With this date or with the following ones it's all OK:
  • new LocalDateTime(new Date(0,0,1,2,30)) — 1900-01-01T02:30:00.000
  • new LocalDateTime(new Date(111,4,24,19,51)) — 2011-05-24T19:51:00.000
But there is something incomprehensible with preceding dates:
  • new LocalDateTime(new Date(0,0,1,2,29,50)) — ...

57. Converting a date string to a DateTime object using Joda Time library

I have date as a string in the following format "04/02/2011 20:27:05". I am using the joda library and would like to convert it to DateTime object. I did:

DateTime dt = ...

58. Jodatime's LocalDateTime is slow when used the first time

I'm currently testing out some webapp technologies in a java project and was wondering why the pages sometimes load fast and sometimes take almost 5s to load. I finally found out that ...

59. Displaying "negative" time periods with Joda-Time PeriodFormatter

I'm using joda-time (1.6.2) on a project and one of the things I'm doing is getting the difference between a predicted time and an actual time. Sometimes this difference is ...

60. joda DateTime parser error

I use jodatime to parse date time strings as follows:

    public static void main(String[]args){
        String s ="16-Jul-2009 05:20:18 PDT";

61. Parsing time strings like "1h 30min"

Anyone know of a Java library that can parse time strings such as "30min" or "2h 15min" or "2d 15h 30min" as milliseconds (or some kind of Duration object). Can Joda-Time ...

62. How do you get the date/time range for "today" using the Joda date/time library in Java?

Assuming this is how you get the current time in Joda time:

DateTime now = new DateTime();
How do you calculate values for the variables dateTimeAtStartOfToday and dateTimeAtEndOfToday? What I'm trying to ...

63. How to get the time difference between 2 dates in millisec using JodaTime

I'm going to design an application, in which I need to get the exact time difference between two dates. Ex:

Date1:31/05/2011 12:54:00
Date2:31/05/2011 13:54:00
I tried using getTime() but I didn't get exact ...

64. Joda Time Zone pattern changing in environments

I am confused about why my date time formatting output for some time zones is changing on my environments. I have a war, I run this war as a standalone war on ...

65. Joda-Time : equivalent of new DateFormatSymbols().getMonths()?

Equivalent of following methods in Joda-Time DateFormatSymbols #getMonths()

 * Gets month strings. For example: "January", "February", etc.
 * @return the month strings.
public String[] getMonths()

66. JODA is acting crazy?

I'm trying to use JODA to simply convert a numeric timestamp (a long representing Unix epoch time), to a Month Day, Year string. Here's code I just ran a few seconds ago:


67. Why does org.joda.time.DateTimeFormatter not parse custom date time with millis correctly?

I have a custom formatter...

// default our time zone to the machine local one.
private static final DateTimeZone LOCAL_TZ = DateTimeZone.getDefault();

// format of date (i.e., timestamp) is yyyy-MM-dd HH:mm:ss.S
private static final DateTimeFormatter ...

68. Using Joda DateTime on the backend, how do I convert to a JavaScript Date object?

I'm using the Joda DateTime object (per SO recommendations) heavily on the Java back-end of my application. But I've not figured out a very consistent way to go ...

69. Joda Period Formatter

System.out.println( PeriodFormat.getDefault().print(Period.hours(1).plusMinutes(30).plusSeconds(60)));
The output from the above Joda PeriodFormatter is "1 hour, 30 minutes and 60 seconds". I know that this is a fringe case, but is there a way to output this ...

70. How to manage pure hh:mm:ss (without any associated date) within jodatime?

For example

DateTime dt=new DateTime(java.sql.Time.valueOf("00:00:00"));
dt.minusMinutes(20); // this line would have no effect!
The problem is that new DateTime set date at "January 1, 1970" A fix could be setting actual date, then it ...

71. get count back of DateTime that where within the correct range - Joda Time

I want to get the count back of DateTime that where within the correct range with Joda Time. I have this version at the moment which is only good to check ...

72. Is there (still) any good reason to use java Date/Time Calender API?

I am tired of using them, Every time I think now I know these APIs I find some thing contradicting, contriving ! I have read lot of evil about them, and ...

73. joda time and ISO8601DateConverter

Hi, I want to convert the ISOdate to the java.util.Date Object.....but i am getting the exception Object c = new ISO8601DateConverter().fromString("1994-01-01T00:00:00"); Converter con=(Converter)c; Calendar cal = Calendar.getInstance(); //Converter cpl=(Converter)c; Date d = (Date) con.convert(java.util.Date.class, "006-02-23T12:34:56"); This trows the following exception, Exception in thread "main" java.lang.ClassCastException: java.util.Date at com.chordiant.cs.dateformate.DateFormat2.main( any help or suggesion is welcome

74. Reasons pro/against moving to joda-time

What are you referring to: The "obvious" part? I meant that I had read numerous articles complaining about Date and Calendar, I had suffered from their clumsy API, I had had to fix strange bugs tracked down to using shared SimpleDateFormat instances; so, considering that date manipulations were central to this application, there was strong incentive to at least evaluate the ...

75. Joda Time

A better way to convert a Duration to millis is to use the getMillis() method: Duration duration = new Period(0, 5, 13, 0).toDurationFrom(new Instant()); long millis = duration.getMillis(); The toDurationFrom() method is needed because the length of a period varies according to the point that you measure it from when you consider a period of days or months (a month could ...