如何在Android中添加30分钟到时间选择器?

时间:2014-02-21 07:55:01

标签: android

在我的应用程序中,我有2个时间选择器对话框。如果我改变从第一个选择器的时间我想要添加30分钟间隔到第二个选择器。例如,如果在第一个选择器中将时间设置为上午11.00,那么第二个应该显示时间为上午11:30。

我怎样才能做到这一点?

TimePickerDialog.OnTimeSetListener listenerTime = new TimePickerDialog.OnTimeSetListener() {
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Date date = new Date();
                if (m_bSimafor) {

                    date.setTime(m_StartDate.getTime());
                    date.setHours(hourOfDay);
                    date.setMinutes(minute);

                    long delta = 0;
                    delta = m_StartDate.getTime() - date.getTime();

                    m_StartDate.setHours(date.getHours());
                    m_StartDate.setMinutes(date.getMinutes());


                    //m_EndDate.setTime(m_EndDate.getTime() - (delta / 2));
                } else {
                    date.setTime(m_EndDate.getTime());
                    date.setHours(hourOfDay);
                    date.setMinutes(minute);

                    if (m_StartDate.getTime() > date.getTime()) {
                        String strMessage = "The end date must be after the start date.";
                        Toast toast = Toast.makeText(m_Context, strMessage,
                                strMessage.length());
                        toast.show();
                        m_EndDate.setTime(m_StartDate.getTime());
                    } else {
                        m_EndDate.setTime(date.getTime());
                    }
                }
                setDateAndTime();
            }

0 个答案:

没有答案