Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9186771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:36:48+00:00 2026-06-17T19:36:48+00:00

I am using Joda-Time to handle dates within an application and found myself perplexed.

  • 0

I am using Joda-Time to handle dates within an application and found myself perplexed.
I need to produce a date using two strings (one for the date, one for the hour of the day).

I have secured the time of day through the use of a RegEx but there are still some dates that go through my RegEx (something like 30th of february for example).

I thought about using the following DateTime construction within a try block (once the substrings are parsed)

DateTime(
    int year,
    int monthOfYear,
    int dayOfMonth,
    int hourOfDay,
    int minuteOfHour
)

and then throw my function’s Exception in the catch block, but according to the api doc, this constructor doesn’t throw the IllegalArgumentException exception I expected to catch, like some others do.

Anyone has any pointer to tell if the MoY/DoM couple form a valid one so as to be able to throw an exception ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:36:49+00:00Added an answer on June 17, 2026 at 7:36 pm

    Although it’s not documented, it will throw org.joda.time.IllegalFieldValueException (a subclass of IllegalArgumentException) if the value is invalid. Sample code:

    import org.joda.time.*;
    
    public class Test {
        public static void main(String[] args) {
            DateTime dt = new DateTime(2012, 2, 30, 0, 0);
            System.out.println(dt);
        }
    }
    

    Result:

    Exception in thread "main" org.joda.time.IllegalFieldValueException: Value 30 for dayOfMonth must be in the range [1,29]
        at org.joda.time.field.FieldUtils.verifyValueBounds(FieldUtils.java:235)
        at org.joda.time.chrono.BasicChronology.getDateMidnightMillis(BasicChronology.java:605)
        at org.joda.time.chrono.BasicChronology.getDateTimeMillis(BasicChronology.java:177)
        at org.joda.time.chrono.AssembledChronology.getDateTimeMillis(AssembledChronology.java:133)
        at org.joda.time.chrono.ZonedChronology.getDateTimeMillis(ZonedChronology.java:119)
        at org.joda.time.chrono.AssembledChronology.getDateTimeMillis(AssembledChronology.java:133)
        at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:254)
        at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:195)
        at org.joda.time.DateTime.<init>(DateTime.java:307)
        at Test.main(Test.java:6)
    

    Obviously it would be nice if this were documented…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Joda-Time library to convert my String dates to a real date,
I need to calculate the time till Christmas in milliseconds. I'm using joda time
I'm implementing a count-down using Joda Time. I only need a display accuracy of
I want to compare(finding remaining days and time between two days) using joda time.
Using Groovy (or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.Date ?
In my application I am using Joda-Time 2.0 but in my WebLogic path there
I have the following problem using Joda-Time for parsing and producing date and time
I am using the Joda-Time library in Java, and have a date and time
I'm learning Android and have need for dates/times. I was recommended Joda-time by a
I have the following code below, I'm trying to compare two dates using Joda

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.