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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:50:30+00:00 2026-06-18T06:50:30+00:00

in my app I’m updating some stuff if the time is between certain hours

  • 0

in my app I’m updating some stuff if the time is between certain hours of the day which the user choose. It works fine if the user chooses something like “07-21”, but not with “21-07” which is over the night.
How I’m doing to check the time is I’m getting the current hour and converting it into milliseconds. Then I check if the current milli is between the chosen hours (those are also converted into milliseconds).
Like this:

    if (currentMilli >= startHourMilli && currentMilli <= endHourMilli) 

The problem: It doesn’t work if the user chooses anything that is over midnight (19-08 for example).

I’ve tried a lot of stuff but I just can’t figure out how to do this.

Any help is appreciated!

  • 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-18T06:50:31+00:00Added an answer on June 18, 2026 at 6:50 am

    Do you increase the day of the year by 1 when you’re passing midnight? Otherwise your
    startHourMilli might be greater than endHourMilli and your if-clause will always be false.

    The solution is to use the add-method of the Calendar class. Therefore I calculate the interval’s length in hours and add this value to our Calendar instance.

    int start = 21; // let's take your failing example: 21-07
    int end = 7;
    int hours = (end - start) % 24; // here hours will be 14
    
    Calendar cal = Calendar.getInstance();
    // set calendar to TODAY 21:00:00.000
    cal.set(Calendar.HOUR_OF_DAY, start);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    
    long startHourMilli = cal.getTimeInMillis();
    
    // add 14 hours = TOMORROW 07:00:00.000
    cal.add(Calendar.HOUR_OF_DAY, hours); 
    long endHourMilli = cal.getTimeInMillis();
    

    Let me know if this helps 🙂

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

Sidebar

Related Questions

My app supports google apis.works fine in phones and emulators which support this. but
App Store We have been developing an app for quite some time now for
App works fine in android 3.2 but not in android 3.1 My application is
My app is working fine but when we upgrade it the 1st time it
My app runs fine on my machine (of course/famous last words). However, when deploying
My app is saving some images on the SD Card, in the AppImages directory
App has fragment activity with framelayout container matching parent. User interacts with fragments ui
My app has the following models: user and watch_list. User has attributes id, name
app.post('/register', express.BodyParser(), function (req, res){ var newu = new UserModel({}); newu.user = req.body.nuser; newu.pass
App with Facebook SDK SSO was working fine in 2.2, now upgraded Samsung Galaxy

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.