Here you can find the source of getTimeList(String start, String end, int pitch)
public static List<String> getTimeList(String start, String end, int pitch)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; public class Main { public static List<String> getTimeList(String start, String end, int pitch, String format) { List<String> result = new ArrayList<String>(); SimpleDateFormat formatter = new SimpleDateFormat(format); try {// w w w. ja v a 2s.co m Date startDate = formatter.parse(start); Date endDate = formatter.parse(end); Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); endCalendar.setTime(endDate); while (startCalendar.before(endCalendar)) { result.add(formatter.format(startCalendar.getTime())); startCalendar.add(Calendar.MINUTE, pitch); } if (startCalendar.equals(endCalendar)) { result.add(formatter.format(startCalendar.getTime())); } } catch (ParseException e) { e.printStackTrace(); } return result; } public static List<String> getTimeList(String start, String end, int pitch) { List<String> result = new ArrayList<String>(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm"); try { Date startDate = formatter.parse(start); Date endDate = formatter.parse(end); Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); endCalendar.setTime(endDate); while (startCalendar.before(endCalendar)) { result.add(formatter.format(startCalendar.getTime())); startCalendar.add(Calendar.MINUTE, pitch); } } catch (ParseException e) { e.printStackTrace(); } return result; } }