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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:18:42+00:00 2026-06-13T22:18:42+00:00

Hello I’d like to convert 24 hr to 12 hr in Android. The time

  • 0

Hello I’d like to convert 24 hr to 12 hr in Android. The time comes from user input in the timepicker dialog, then display it in a textview. If the user clicks on the PM button in the picker dialog, it should automatically display that in a textview. For examaple, the user clicks on 3:00 AM, it should display in the textview as 3:00 AM, while another user clicks on 3:00 PM, it should display in the textview 3:00 PM not 15:00. Any help please?

Please do check the code I have below:

            public void onTimeSet( TimePicker view, int selectedHour,
                int selectedMinute ) {
            // Gets current time
            Calendar c = Calendar.getInstance();

            hour = selectedHour;
            minute = selectedMinute;


            // set waking time into textview

           String getWT = wakingtime.getText().toString();
           wakingtime.setText( new StringBuilder().append( pad( hour ))
                    .append( ":" ).append( pad( minute ))); 


            // Assign hour set in the picker
            c.set( Calendar.HOUR, selectedHour );
            c.set( Calendar.MINUTE, selectedMinute );

            // Have Calendar calculate the substraction of hours and minutes
            c.add( Calendar.HOUR, SUB_HOUR );
            c.add( Calendar.MINUTE, SUB_MINUTE );

            // Get the hour and the minute calculated
            hour = c.get( Calendar.HOUR );
            minute = c.get( Calendar.MINUTE );

I beg your pardon if you don’t see any formatting..

  • 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-13T22:18:43+00:00Added an answer on June 13, 2026 at 10:18 pm

    Changue this:

        wakingtime.setText( new StringBuilder().append( pad( hour ))
                            .append( ":" ).append( pad( minute ))); 
    

    By this:

    StringBuilder sb = new StringBuilder();
    if(hour>=12){                      
        sb.append(hour-12).append( ":" ).append(minute).append(" PM");
    }else{
        sb.append(hour).append( ":" ).append(minute).append(" AM");
    }
    wakingtime.setText(sb);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! I've been programming for a long time but just started developing for android,
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello i have a TextField on my scene. It haves only digits, user input
Hello guys I am seeking help when it comes to getting text from an
Hello ! I need to create a report like the attachment shows with Jasper
Hello and thank you for taking the time to help me solve my problem.
hello for my app I need to save a record that the user type,
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello everyone i am developing an quiz based app in android and i have
Hello everyone i am trying to format the input number range with php number_format

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.