001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.utility; 017 018import java.text.DecimalFormat; 019 020public class DateTimeUtil { 021 022 public static String formatTime(long endTime, long startTime) { 023 long milliseconds = endTime - startTime; 024 return formatTime(milliseconds); 025 } 026 027 public static String formatTime(long timeInMillisec) { 028 long hours; 029 long minutes; 030 long seconds; 031 long milliseconds = timeInMillisec; 032 double secAndMilliSec = (double) timeInMillisec / 1000; 033 double milliSec = secAndMilliSec - (long) secAndMilliSec; 034 DecimalFormat df = new DecimalFormat("#.###"); 035 seconds = (milliseconds / 1000); 036 // milliseconds = milliseconds - seconds * 1000; 037 minutes = seconds / 60; 038 seconds = seconds - minutes * 60; 039 hours = minutes / 60; 040 minutes = minutes - hours * 60; 041 secAndMilliSec = (double) seconds + Double.valueOf(df.format(milliSec)); 042 String timeTaken = hours + ":" + minutes + ":" + Double.valueOf(df.format(secAndMilliSec)); 043 return timeTaken; 044 } 045 046}