从2020-10-18 00:00 ~2020-10-19 24:45
for (int j = 0; j <95; j++) {
int time = j * 15;
int hour = (int) Math.floor(time / 60); //舍弃小数去整数
String hour2 = hour > 9 ? hour + "" : "0" + hour; //三元运算符,得到小时格式xx:00
String minute = String.valueOf(time % 60); //初始整时的余数即为分钟数
minute = Integer.parseInt(minute) > 9 ? minute : "0" + minute; //当余数小于9时的时间格式
String currenttime = hour2 + ":" + minute;
}
时间增加一天的方法
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(currentdate); //将字符串转成日期对象
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);//设置日历的时间
calendar.add(calendar.DATE, 1);// 日期向后+1天,整数往后推,负数向前推
date = calendar.getTime(); //获取日历时间
String newdate = sdf.format(date);