java - 在 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);
}
解决方案
推荐阅读
- javascript - js - 与 0 的比较总是返回 true?
- python - 创建 csv 文件,其中每一行是一个列表中的一些嵌套列表
- javascript - React Hooks - useState 不会立即更新“正在保存...”、“已保存”状态
- python - 有没有办法模拟网络,以便我可以测试用 python 编写的 p2p 网络代码?
- python - 模型输入必须来自 `tf.keras.Input` ...,它们不能是先前非输入层的输出
- excel - 如何使用 VBA 查找日期不一致
- javascript - 如何在其中一个建议 selectize.js 中禁用自动选择?
- javascript - 如何在画布上找到图像坐标?
- reactjs - 无法在反应中给予 Axios POST 请求
- python - 如何将转换应用于火炬张量