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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:22:06+00:00 2026-06-16T11:22:06+00:00

How can I determine if the current time is between two other time objects?

  • 0

How can I determine if the current time is between two other time objects?

For example: current: 15:23, startTime: 22:00, endTime: 06:00. So the current time is not between this two other times, but this “23:47” is.

*I don’t care about the date only the time

I tried to do it like this:

Time startTime = getStartTime();
Time endTime = getEndTime();

Calendar c = Calendar.getInstance();
Time now = new Time(c.getTimeInMillis());

if (now.before(endTime) && now.after(startTime)) {
    return true;
}

return false;

but it dosen’t work well. their aren’t any error but it just dosen’t work.

To be more precise the problem is that 15:35.after(22:00) return true… and I don’t know why.
I think that the problem is something with the dates but I don’t know what

  • 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-16T11:22:07+00:00Added an answer on June 16, 2026 at 11:22 am

    I found a solution:

        Time startTime = getStartTime();
        Time endTime = getEndTime();
    
        Calendar startCalendarTime = Calendar.getInstance();
        startCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, startTime.getHours(), startTime.getMinutes(), 0);
    
        Calendar endCalendarTime = Calendar.getInstance();
        endCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, endTime.getHours(), endTime.getMinutes(), 0);
    
        Calendar midnightTime = Calendar.getInstance();
        midnightTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 23, 59, 0);
    
        Calendar nowCalendarTime = Calendar.getInstance();
        nowCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH);
    
        if (startCalendarTime.after(endCalendarTime)) {
    
            if (nowCalendarTime.after(midnightTime)) {
                startCalendarTime.add(Calendar.DAY_OF_YEAR, -1);
            } else {
                endCalendarTime.add(Calendar.DAY_OF_YEAR, 1);
            }
    
        }
        int hours = nowCalendarTime.getTime().getHours();
        int minutes = nowCalendarTime.getTime().getMinutes();
        nowCalendarTime.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, hours, minutes, 0);
    
        if (nowCalendarTime.after(startCalendarTime) && nowCalendarTime.before(endCalendarTime)) {
            return true;
        }
    
        return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can determine the current number of connections by db.serverStatus().connections but all that gives
I'm currently trying to determine the amount of time between two dates (one of
How can I determine the current date and time of various countries using a
Is there a sensible way to determine whether the current user can access an
Using php I'd like to subtract/minus two times; each time within a separate document
How can you determine and compare (>, <, etc.) the current OS version of
I have a program that collects objects over time. Those objects are often, but
Can somebody please let me know how we can determine if a local disk
How can I determine the absolute path of a file or directory from a
How can I determine the used size/length of a buffer created with create_string_buffer? buffer

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.