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 7750979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:25:52+00:00 2026-06-01T11:25:52+00:00

I am wanting to adjust 3 Gregorian Calendar dates in Java, with one to

  • 0

I am wanting to adjust 3 Gregorian Calendar dates in Java, with one to be 24 hours before, the other 48, hours before and last 78 hours before. I had been using Calendar.HOUR and changed this to Calendar.HOUR_OF_DAY.

Since I did this my code stopped working. I am comparing the adjusted dates with their original values using a method that uses date1.before(date2) and date1.after(date2) to get a comparisonflag
which can be 1 or 0 which I then use in my code.

I was wondering how to do the adjust the HOUR_OF_DAY in my dates to then achieve
the above.

  • 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-01T11:25:53+00:00Added an answer on June 1, 2026 at 11:25 am

    Some code would have been nice. But if I understand the problem correctly:

    From the javadoc of Calendar:

    HOUR is used for the 12-hour clock. E.g., at 10:04:15.250 PM the HOUR is 10.
    HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.
    

    When adding/substracting hours from a date:

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, -24);
    cal.add(Calendar.HOUR_OF_DAY, -24);
    

    This should have the same effect.

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

Sidebar

Related Questions

Wanting to use: Ajax Event Calendar but the dates are in american format, how
Wanting to make sure I'm using classes properly. The main script accepts this from
Im wanting to organize a series of dates in the following format. As a
Using PCRE lib...wanting to look for a string of words up to a known
I am using some custom controls one of which is a tooltip controller that
Wanting to check if I missed a setting somewhere, or if I'm just using
I am wanting to learn Java, particularly for Android development since I am getting
I'm wanting to start a WPF application using caliburn.micro so I can use TDD
I wanting to reproject the vertices of my polygon. I have been able to
Wanting to implement authentication by client certificates I am experiencing some issues. First some

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.