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

  • SEARCH
  • Home
  • 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 4112370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:11:13+00:00 2026-05-20T22:11:13+00:00

I want to set up joda DateTime to today at 2 AM (see sample

  • 0

I want to set up joda DateTime to today at 2 AM (see sample code below). But I’m getting this exception:

Exception in thread "main" org.joda.time.IllegalFieldValueException: Value 2 for hourOfDay is not supported: Illegal instant due to time zone offset transition: 2011-03-27T02:52:05.239 (Europe/Prague)
at org.joda.time.chrono.ZonedChronology$ZonedDateTimeField.set(ZonedChronology.java:469)
at org.joda.time.MutableDateTime.setHourOfDay(MutableDateTime.java:702)

What is the correct way to the handle exception above or to create a DateTime at a particular hour of day?

Sample code:

MutableDateTime now = new MutableDateTime();
now.setHourOfDay(2);
now.setMinuteOfHour(0);
now.setSecondOfMinute(0);
now.setMillisOfSecond(0);
DateTime myDate = now.toDateTime();

Thanks.

  • 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-05-20T22:11:14+00:00Added an answer on May 20, 2026 at 10:11 pm

    It seems like you’re trying to get from a specific local time to a DateTime instance and you want that to be robust against daylight savings. Try this… (note I’m in US/Eastern, so our transition date was 13 Mar 11; I had to find the right date to get the exception you got today. Updated my code below for CET, which transitions today.) The insight here is that Joda provides LocalDateTime to let you reason about a local wall-clock setting and whether it’s legal in your timezone or not. In this case, I just add an hour if the time doesn’t exist (your application has to decide if this is the right policy.)

    import org.joda.time.DateTime;
    import org.joda.time.DateTimeZone;
    import org.joda.time.LocalDateTime;
    
    class TestTz {
    
      public static void main(String[] args)
      {
         final DateTimeZone dtz = DateTimeZone.forID("CET");
         LocalDateTime ldt = new LocalDateTime(dtz)
           .withYear(2011)
           .withMonthOfYear(3)
           .withDayOfMonth(27)
           .withHourOfDay(2);
    
        // this is just here to illustrate I'm solving the problem; 
        // don't need in operational code
        try {
          DateTime myDateBorken = ldt.toDateTime(dtz);
        } catch (IllegalArgumentException iae) {
          System.out.println("Sure enough, invalid instant due to time zone offset transition!");
        }
    
        if (dtz.isLocalDateTimeGap(ldt)) {
          ldt = ldt.withHourOfDay(3);
        }
    
        DateTime myDate = ldt.toDateTime(dtz);
        System.out.println("No problem: "+myDate);
      }
    
    }
    

    This code produces:

    Sure enough, invalid instant due to time zone offset transition!
    No problem: 2011-03-27T03:00:00.000+02:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want set default icon of some extension by C#. But this gives me
i have one textfield for input some serial number code.i want set this code
I want set Listbox background to transparent but not working Is there any idea?
i want set class for repeater when doPostBack for those dataID i wan but
i have a multiple marker Google map, it works fine but i want set
I want to set a repeating alarm monthly; but my app resets the alarm
I want to set the type of a list to be ints but I
i want set width for PdfpCell in Table, i want design this i Write
I want set different access for different modules. I tried out $this->allow($role, $module, $controller,
i want set value of input type if condition is true but my function

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.