一个时间进去 五个时间出来 每个多五分钟
public static void main(String[] args) {
String[] strings = timeToTimes("2018-07-16 17:45");
for (String string : strings) {
System.out.println(string);
}
}
private static String[] timeToTimes(String s) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String[] strings = new String[5];
String s1 = datePlus(s, sf);
strings[0] = s1;
for (int i = 1; i < strings.length; i++) {
strings[i] = datePlus(strings[i - 1], sf);
}
return strings;
}
private static String datePlus(String d, DateFormat sf) {
Date date = null;
try {
date = sf.parse(d);
} catch (ParseException e) {
e.printStackTrace();
}
//五分钟就是300000毫秒
Date nextDate = new Date(date.getTime() + 300000);
return sf.format(nextDate);
}
网友评论