Date date =newDate();DateFormat simpleDateFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");Stringto= simpleDateFormat.format(date);Calendar calendar =Calendar.getInstance();
calendar.setTime(date);// 设置为当前时间
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)-1);// 设置为上一个月
date = calendar.getTime();String from = simpleDateFormat.format(date);
传入时间范围获取其中的所有天数 //格式化为年月
SimpleDateFormat sdf =newSimpleDateFormat("yyyy-MM-dd");Calendar min =Calendar.getInstance();Calendar max =Calendar.getInstance();
min.setTime(sdf.parse(startTime));
min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), min.get(Calendar.DATE),0,0,0);
max.setTime(sdf.parse(endTime));
max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), max.get(Calendar.DATE),23,59,59);Calendar curr = min;while(curr.before(max)){MergeIndexScheduledReady.mergeQueue.add(sdf.format(curr.getTime()));
curr.add(Calendar.DATE,1);}
时间格式字符串转换
val format =newSimpleDateFormat("E MMM dd hh:mm:ss z yyyy",Locale.US)
val timeStr =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")