Here you can find the source of getdaysslice(String startdate, String enddate)
public static int getdaysslice(String startdate, String enddate)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static int getdaysslice(String startdate, String enddate) { if (startdate == null || "".equals(startdate.trim())) return 0; if (enddate == null || "".equals(enddate.trim())) return 0; SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date start = null; java.util.Date end = null; try {//w w w . j a v a 2s . c o m start = myFormatter.parse(startdate); end = myFormatter.parse(enddate); } catch (Exception e) { return 0; } long daynum = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000); Calendar startcalendar = new GregorianCalendar(); startcalendar.setTime(start); int n = 0; for (int i = 0; i <= daynum; i++) { if (startcalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || startcalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { startcalendar.add(Calendar.DAY_OF_MONTH, 1); continue; } startcalendar.add(Calendar.DAY_OF_MONTH, 1); n++; } return n; } public static String getTime() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); String min; min = dateString.substring(14, 16); return min; } }