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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:33:57+00:00 2026-06-17T09:33:57+00:00

Mac OS-X ECLIPSE with ADT ANDROID ……………. Problem: When I pick the time, say

  • 0

Mac OS-X

ECLIPSE with ADT

ANDROID

…………….

Problem: When I pick the time, say 06:00, it sets the time as 18:00, when I pick the time 18:00 it sets the time as 06:00. I can’t seem to figure out why.

…………….

LOGIC

Gets current date instance.

OnClickListener is set to a ButtonImage.

OnClick calls showTimeDialog with 2 arguments (a TextView, the current date instance).

TimePicker Dialog shows with at a set time of 09:00.

TimeSet sets the time of a Calendar activeTime and updates a TextView

…………..

ADDITIONAL NEW INFO

Ok, so strange thing happened, now my code seems to work, BUT last time I checked it was before 24:00 and it was acting as described. It works now and the time is 00:20 here in the UK. I dont know if this has anything to do with it but I will update this post if anything changes.

ADDITIONAL NEW INFO 2

My code seems to work between 00:00 – 12:00 but from 12:00 – 24:00 it doesn’t. I’m stumped..

………….

Here is my code:

    /////// SETUP TIME

    //  capture our View elements for the start time function
    startTimeDisplay = (TextView) findViewById(R.id.editText2);
    endTimeDisplay = (TextView) findViewById(R.id.editText3);
    startPickTime = (ImageButton) findViewById(R.id.imageButtonStartTime);
    endPickTime = (ImageButton) findViewById(R.id.imageButtonEndTime);

    // Use the current time as the default values for the time picker
    startTime = Calendar.getInstance();
    endTime = Calendar.getInstance();
    startTime.get(Calendar.DATE);
    endTime.get(Calendar.DATE);

    // add a click listener to the button
    startPickTime.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showTimeDialog(startTimeDisplay, startTime);
        }
    });

    /* add a click listener to the button   */
    endPickTime.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showTimeDialog(endTimeDisplay, endTime);
        }
    });
}
@Override
protected Dialog onCreateDialog(int id) {

    getTime(activeTime);
    int hr = activeTime.get(Calendar.HOUR_OF_DAY);
    int mn = activeTime.get(Calendar.MINUTE);

    Log.d(TAG, "first hr..." +hr);
    Log.d(TAG, "first mn..." +mn);


    switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this, dateSetListener, activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
        case TIME_DIALOG_ID:
            return new TimePickerDialog(this, timeSetListener, THE_HOUR, THE_MINUTE, true);
    }
    return null;
}

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    super.onPrepareDialog(id, dialog);

    getTime(activeTime);
    int hr = activeTime.get(Calendar.HOUR_OF_DAY);
    int mn = activeTime.get(Calendar.MINUTE);

    Log.d(TAG, "second hr..." +hr);
    Log.d(TAG, "second mn..." +mn);

    switch (id) {
        case DATE_DIALOG_ID:
            ((DatePickerDialog) dialog).updateDate(activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
            break;
        case TIME_DIALOG_ID:
            ((TimePickerDialog) dialog).updateTime(THE_HOUR, THE_MINUTE);
            break;
    }
}

public void showTimeDialog(TextView timeDisplay, Calendar date) {
    activeTimeDisplay = timeDisplay;
    activeTime = date;
    showDialog(TIME_DIALOG_ID);
}

private OnTimeSetListener timeSetListener = new OnTimeSetListener() {
    @Override
    public void onTimeSet(TimePicker view, int hour, int minute) {
        activeTime.set(Calendar.HOUR, hour);
        activeTime.set(Calendar.MINUTE, minute);
        updateTimeDisplay(activeTimeDisplay, activeTime);
        unregisterTimeDisplay();
    }
};

private void updateTimeDisplay(TextView timeDisplay, Calendar date) {

    //convert Calendar to Unix Time
    long activeTimeUnixTime = (long) (date.getTimeInMillis());

    //convert Unix Time to Date
    java.util.Date startTimeDate = new java.util.Date(activeTimeUnixTime);

    //convert Date to SimpleDateFormat and convert to String
    SimpleDateFormat formatter2;
    formatter2 = new SimpleDateFormat("kk:mm", Locale.UK);
    String stringTime = formatter2.format(startTimeDate);

    timeDisplay.setText(stringTime);
}

private void unregisterTimeDisplay() {
    activeTimeDisplay = null;
    activeTime = null;
}
  • 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-17T09:33:58+00:00Added an answer on June 17, 2026 at 9:33 am

    SOLUTION:

    My onTimeSetListener onTimeSet() method was using HOUR instead of HOUR_OF_DAY.

    Okay so I was stuck on this for ages but finally figured it out. But because Im quite new to Android and Calendar the difference alluded me.

    Calendar.HOUR is 5 for 17:00 because it’s the 5th hour in the PM. Calendar.HOUR_OF_DAY returns 17 for 17:00. So here is the correct code:

    private OnTimeSetListener timeSetListener = new OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            activeTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
            activeTime.set(Calendar.MINUTE, minute);
            updateTimeDisplay(activeTimeDisplay, activeTime);
            unregisterTimeDisplay();
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Mac OS-X Android Eclipse with ADT SQLite I'm new to creating Android Apps and
[2010-12-17 07:37:12 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read /Users/macuser/android-sdk-mac/AndroidManifest.xml: java.io.FileNotFoundException: /Users/macuser/android-sdk-mac/AndroidManifest.xml (No such file or
I am using Eclipse Juno on Mac OS 10.7.4 and Android ADT. Some times
Using Mac OS X 10.6.2, Eclipse SDK 3.5.2. I installed the Android plugin, following
I've just set up my first Android development environment consisting of Eclipse 3.5 Mac
I am trying to bring an Android project from Eclipse Mac to a PC.
I have imported the android project in Eclipse on Mac System, I got Error
I have a simple app HelloWorld Android app in Eclipse (Mac OS X), when
I'm using Eclipse on mac for developing android apps. When I run the application
everybody, I am facing a weird problem in mac osx. I have installed eclipse(Indigo

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.