Here you can find the source of calcRealTime(Timestamp beginTime, Timestamp endTime)
public static long calcRealTime(Timestamp beginTime, Timestamp endTime)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.util.Calendar; public class Main { public static long calcRealTime(Timestamp beginTime, Timestamp endTime) { Calendar beginC = getRealCalendar(beginTime); Calendar endC = getRealCalendar(endTime); long span = (endC.getTimeInMillis() - beginC.getTimeInMillis()) / 1000; long a = span / (86400 * 7); long b = span % (86400 * 7); long c = b / 86400; long d = b % 86400; if (endC.get(Calendar.DAY_OF_WEEK) < beginC.get(Calendar.DAY_OF_WEEK) || endC.get(Calendar.DAY_OF_WEEK) == beginC.get(Calendar.DAY_OF_WEEK) && c == 6) c -= 2;/*from w w w .ja v a 2s.co m*/ if (d >= 32400) d -= 54000; return (32400 * 5) * a + 32400 * c + d; } protected static Calendar getRealCalendar(Timestamp time) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(time.getTime()); if (c.get(Calendar.DAY_OF_WEEK) == 6 && c.get(Calendar.HOUR_OF_DAY) >= 19) { c.setTimeInMillis(c.getTimeInMillis() + 86400000 * 3); clearTime(c); return c; } if (c.get(Calendar.DAY_OF_WEEK) == 7) { c.setTimeInMillis(c.getTimeInMillis() + 86400000 * 2); clearTime(c); return c; } if (c.get(Calendar.DAY_OF_WEEK) == 1) { c.setTimeInMillis(c.getTimeInMillis() + 86400000); clearTime(c); return c; } if (c.get(Calendar.HOUR_OF_DAY) >= 10 && c.get(Calendar.HOUR_OF_DAY) < 19) return c; if (c.get(Calendar.HOUR_OF_DAY) >= 19) c.setTimeInMillis(c.getTimeInMillis() + 86400000); clearTime(c); return c; } protected static void clearTime(Calendar c) { c.set(Calendar.HOUR_OF_DAY, 10); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); } }