Incorrect timing

I have a date and time in my application, and I just noticed that the time is wrong. the current time that the timer displays is an hour delay, and its am / pm is not the same as, for example, the current time 2:55 pmit will show 1:55 amwhat appears to be a problem, this is the code

UPDATE: DATE AND TIME PICKER

@Override
public void onClick(View v) {

    if (v == btnCalendar) {

        // Process to get Current Date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DATE)+1;

        // Launch Date Picker Dialog
        DatePickerDialog dpd = new DatePickerDialog(this,
                new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year,
                            int monthOfYear, int dayOfMonth) {
                        // Display Selected date in textbox
                        txtDate.setText(dayOfMonth + "-"
                                + (monthOfYear + 1) + "-" + year);

                    }
                }, mYear, mMonth, mDay);
        dpd.show();
    }
    if (v == btnTimePicker) {

        // Process to get Current Time
        final Calendar c = Calendar.getInstance();
        mHour = c.get(Calendar.HOUR)+1;
        mMinute = c.get(Calendar.MINUTE);

        // Launch Time Picker Dialog
        TimePickerDialog tpd = new TimePickerDialog(this,
                new TimePickerDialog.OnTimeSetListener() {

                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay,
                            int minute) {
                        // Display Selected time in textbox
                        txtTime.setText(hourOfDay + ":" + minute);
                    }
                }, mHour, mMinute, false);
        tpd.show();
    }
}
}

UPDATE: what I did was put +1 in mHour = c.get(Calendar.HOUR_OF_DAY)+1;, maybe there are any ideas on this method?

unixed - AM / PM button is incorrect, it always shows am at the beginning

UPDATE: AM / PM does not start with am completely wrong, because now that its morning shows pm, but at pm it shows am

UPDATE: there is also a problem in date.What have I done to put +1 in mDay = c.get(Calendar.DATE)+1;maybe set back on this method any ideas?

+3
2

- :

 <TimePicker
            android:id="@+id/timePicker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/datePicker1"
            android:layout_centerHorizontal="true"
            android:layout_margin="20dp" />

TimePicker tp = (TimePicker)findViewById(R.id.timePicker);

 btn.setOnClickListener(new OnClickListener() 
 {

            @Override
            public void onClick(View v) 
            {
                // TODO Auto-generated method stub

                int Hour = tp.getCurrentHour();
                int Minute = tp.getCurrentMinute();

                    txtTime.setText(String.valueOf(Hour) + ":" + String.valueOf(Minute));

            }
        });
0

All Articles