首页 > 解决方案 > 在 Android 中比较时间?

问题描述

我有两次打开和关闭。我想生成尽可能多的插槽,可以在固定分钟数的定义范围内容纳。例如,开放时间:下午 12:30 和关闭时间:分别为下午 3:30。所以在这个特定的范围内,我必须增加分钟,比如说每次增加 15 分钟,直到时间到达关闭时间。就像 12:45, 12:30, ........ , 3:15, 3:30 pm 正是在这里我想完成循环但在我的情况下它从 12:30 上升到凌晨 12:06下午

        String newTime = "";
        SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
        Date date = dateFormat.parse(_model.getClinic_time_from());
        SimpleDateFormat dateFormat1 = new SimpleDateFormat("hh:mm a");
        Date date1 = dateFormat1.parse(_model.getClinic_time_to());

        Date temp = date;
        while (date1.compareTo(temp) < 0)
            {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(temp);
                calendar.add(Calendar.MINUTE, Integer.parseInt(_model.getSlot()));
                newTime = dateFormat.format(calendar.getTime());
                Apt_time_model ap = new Apt_time_model(dateFormat.format(temp.getTime()),newTime,"no status");

                    Apt_time_model ap1 = new Apt_time_model(ap.getApt_time_from(), ap.getApt_time_to(),ap.getStatus());
                    list.add(ap1);
                temp = dateFormat.parse(newTime);
            }

标签: javaandroidandroid-calendarandroid-timepickerandroid-timer

解决方案



推荐阅读