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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:56:25+00:00 2026-06-17T06:56:25+00:00

In a bit of a problem. I have a onClick that when clicked will

  • 0

In a bit of a problem. I have a onClick that when clicked will get the current time and add a certain number of hours and minutes. The code below is what I have and it currently sends the data to another Activity and displays it, except it doesn’t change the hours.

public void onClickHere (View v) {

    String ti1me, ti2me, ti3me;

    //carry out calculation
    LocalTime localtime = new LocalTime();
    LocalTime dt = new LocalTime(localtime);

        //Add two hours and subtract 10 minutes
        LocalTime twoHoursLater = dt.plusHours(2);
                  twoHoursLater = dt.minusMinutes(10);

        //Add three hours and 9 minutes
        LocalTime threeHoursLater = dt.plusHours(3);
                  threeHoursLater = dt.plusMinutes(9);

        //Add five hours and subtract 8 minutes
        LocalTime fiveHoursLater = dt.plusHours(5);
                  fiveHoursLater = dt.minusMinutes(8);


    DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
    ti1me = (twoHoursLater.toString(formatter));
    ti2me = (threeHoursLater.toString(formatter));
    ti3me = (fiveHoursLater.toString(formatter));

    Intent i = new Intent(this, WakeUpMain.class);
    i.putExtra("time1", ti1me);
    i.putExtra("time2", ti2me);
    i.putExtra("time3", ti3me);
    startActivity(i);

}

As you can see I’m trying to get three times, and adding various minutes and hours to both, the minutes add fine but the hour stays with the current time, or changes based on how the minutes are added and whether it carries into the next hour.

It’s 11:22 as I type this and if I run the app and click the button the outputs are:
11:11
11:31
11:14

The hours aren’t changing. Is there a way to fix this? The hour only changes when for example the time is 11:05, the first time would then show up as 10:55.

Would appreciate any help. Really confusing me.

  • 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-17T06:56:27+00:00Added an answer on June 17, 2026 at 6:56 am

    When you adding minutes you flush your hours increment:

    twoHoursLater = dt.minusMinutes(10);
    

    Use

    LocalTime twoHoursLater = dt.minusMinutes(10);
        twoHoursLater = twoHoursLater.plusHours(2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of a problem that I can't seem to code my
Hey guys, I have a bit of a problem that I can't solve. I'm
I'm having a bit of a jQuery problem. Basically I have some functions that
I have this bit of code that repeates. <div class='commentfloatleft'> <button type='button' class='button2' onclick='upvote($id8)'>
I have a problem with an existing ASP.Net Mobile Website that current renders correctly
I have a bit of problem when trying to validate my page as HTML5.
I have a bit of a problem. I am trying to do the following
So I have a little bit of a problem. I working on a project
I have a bit of a problem building my project. I'm getting the bellow
I have a bit of a problem here. I have a third party ActiveX

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.