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

  • Home
  • SEARCH
  • 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 8589357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:02:18+00:00 2026-06-11T23:02:18+00:00

In my app, I am showing time in text view as 07:00 PM. On

  • 0

In my app, I am showing time in text view as 07:00 PM. On click of the text view, a time picker dialog pops up, In that time picker, I have to show exactly the same time as what is appearing in textview. But, I am not getting how to do that.

CODE

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm a");
        //int hr = 0;
        Date date = null;
        try 
        {
            date = sdf.parse(resDateArray[3]);
        } 
        catch (ParseException e) {
            e.printStackTrace();
        }
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //tp is reference variable for time picker

        tp.setCurrentHour(calendar.get(Calendar.HOUR));
        tp.setCurrentMinute(calendar.get(Calendar.MINUTE));

        }//else
  • 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-11T23:02:20+00:00Added an answer on June 11, 2026 at 11:02 pm

    You should use a SimpleDateFormat to get a Date object from your String.
    Then just call

    picker.setCurrentHour(date.getHours())
    

    and

    picker.setCurrentMinute(date.getMinutes())
    

    Since the Date object is deprecated, you should use a Calendar instead of it.
    You can instantiate a Calendar this way:

    Calendar c = Calendar.getInstance();
    c.setTime(date);
    picker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    picker.setCurrentMinute(c.get(Calendat.MINUTE));
    

    Edit: the complete code:

    import java.util.Date;
    import java.text.SimpleDateFormat; //Don't use "android.icu.text.SimpleDateFormat"
    import java.text.ParseException; //Don't use "android.net.ParseException"
    
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
    Date date = null;
    try {
        date = sdf.parse("07:00");
    } catch (ParseException e) {
    }
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    
    TimePicker picker = new TimePicker(getApplicationContext());
    picker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    picker.setCurrentMinute(c.get(Calendar.MINUTE));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a widget that shows various images with text below, and the same
I need to capture the event when my app is showing a dialog and
Here is the error I get ArgumentError in External_articles#show Showing app/views/external_articles/show.html.erb where line #3
I am showing a dialog in an iOS app to allow users to select
I'm on an AR app for iOS for showing annotations on a camera view
I'm working on an iphone app and want to have a page showing multiple
I am creating an app which is a guide. I have a photograph showing
I've set up my app exactly in line with the Railscasts Time Zone Episode
I have an iOS app that posts to users FB feeds with a link,
in my app i an showing a list view. The list view is a

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.