public static ArrayList buildTimemap(){
ArrayList al = new ArrayList();
al.add("09:00");
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH,
9, 29, 0);
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date d = c.getTime();
String time = df.format(d);
while (!time.equals("11:30")) {
c.add(Calendar.MINUTE, 1);
d = c.getTime();
time = df.format(d);
// System.out.println(time);
timeMap.put(time, "");
al.add(time);
}
c.add(Calendar.MINUTE, 89);
while (!time.equals("15:00")) {
c.add(Calendar.MINUTE, 1);
d = c.getTime();
time = df.format(d);
// System.out.println(time);
timeMap.put(time, "");
al.add(time);
}
return al;
}
ArrayList al = new ArrayList();
al.add("09:00");
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH,
9, 29, 0);
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date d = c.getTime();
String time = df.format(d);
while (!time.equals("11:30")) {
c.add(Calendar.MINUTE, 1);
d = c.getTime();
time = df.format(d);
// System.out.println(time);
timeMap.put(time, "");
al.add(time);
}
c.add(Calendar.MINUTE, 89);
while (!time.equals("15:00")) {
c.add(Calendar.MINUTE, 1);
d = c.getTime();
time = df.format(d);
// System.out.println(time);
timeMap.put(time, "");
al.add(time);
}
return al;
}
本文详细介绍了如何使用Java编程语言构建时间映射的算法,包括使用Calendar类和SimpleDateFormat进行日期时间操作,实现从早上9点到中午11点30分,再到下午3点的时间序列生成。
2061

被折叠的 条评论
为什么被折叠?



