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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:53:17+00:00 2026-05-30T22:53:17+00:00

I’m working on an android application, as part of me trying to learn android

  • 0

I’m working on an android application, as part of me trying to learn android programming, that will switch audio profiles based on day and time (provided by the user)… So far I have got most of the layout done, I have also created a service that will run in the background to perform few checks…

Right now I’m having a hard time trying to find an elegant way to handle checking if current time falls in time range saved by the user… I’m saving the user’s preference for time range in a string format from androids TimerPicker control, I need to check if the current time falls in the user saved times…

Right now I have the following code:

the ‘from time’ is coming in with the following: hour:minute:AM/PM — 8:59:AM in string format

the ‘to time’ is coming in with the following: hour:minute:AM/PM — 4:59:PM in string format

if(fromAMPM.equals("AM")){
        from.set(from.AM_PM, from.AM);
} else {
        from.set(from.AM_PM, from.PM);
}

//dont care about the YEAR and MONTH, so set it to current MONTH and YEAR                                      
from.set(rightNow.get(rightNow.YEAR), rightNow.get(rightNow.MONTH), dayOfWeek, fromHour, fromMinute);                  

if(toAMPM.equals("AM")){
        to.set(to.AM_PM, to.AM);
}else{
        to.set(to.AM_PM, to.PM);
}      

//dont care about the YEAR and MONTH, so set it to current MONTH and YEAR                      
to.set(rightNow.get(rightNow.YEAR), rightNow.get(rightNow.MONTH), dayOfWeek, toHour, toMinute);

//this is just for me to see what got set:
SimpleDateFormat df3 = new SimpleDateFormat("HH:mm aaa");  
String formattedDate1 = df3.format(from.getTime());
String formattedDate2 = df3.format(to.getTime());

After all this processing:

formattedDate1 is returning: 08:59 AM

formattedDate2 is returning: 04:59 AM

Any suggestions?

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-30T22:53:18+00:00Added an answer on May 30, 2026 at 10:53 pm

    Take a look at the Calendar documentation, under the section “Inconsistent Information”

    http://developer.android.com/reference/java/util/Calendar.html

    You call:

    to.set(rightNow.get(rightNow.YEAR), rightNow.get(rightNow.MONTH), dayOfWeek, toHour, toMinute);

    Which sends toHour as HOUR_OF_DAY (24h), not HOUR (12h).

    It says that when you supply it with inconsistent information, it just uses the latest information. You’re telling it that toHour is 4 on a 24hour scale, which is inconsistent with your PM setting, so it throws the PM setting away.

    The easiest change would probably be just to add 12 to toHour instead of setting the AM_PM. Or, don’t use the set(year, month, day, hourofday, minute) command and just set hour and am_pm separately.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.