# import java.util.*; public class Timer { public static void main(String args[]) { // create start and end calendar objects Calendar sTime=Calendar.getInstance(); Calendar eTime=Calendar.getInstance(); // now set times -- add routines to get from sio or file // be sure to verify times are in range !! // adjust times for early start and late finish sTime.set(Calendar.HOUR_OF_DAY,8);sTime.set(Calendar.MINUTE,0); eTime.set(Calendar.HOUR_OF_DAY,16);eTime.set(Calendar.MINUTE,0); long span=timeSpan(sTime,eTime); // adjust time for lunch hour here long secs=span/1000;long mins=secs/60;long hours=mins/60; System.out.println(hours); System.out.println(mins); } // timeSpan (calendarObject,calendarObject) returns long milliseconds public static long timeSpan(Calendar calStart,Calendar calEnd) { Date sTime1,eTime1;long interval,sTime2,eTime2; sTime1=calStart.getTime();eTime1=calEnd.getTime(); // to Date objects sTime2=sTime1.getTime();eTime2=eTime1.getTime(); // to long objects interval=eTime2-sTime2;return interval; } }
0 意見:
張貼留言