一般用于记录方法所用时间
import android.os.SystemClock;import java.util.HashMap;/** * * 用于方便的记录当前与开始时间的差值 * Created by wangxingsheng on 16/8/16. */public class TimeRecordUtil { private static final String TAG = "TimeRecordUtil "; private HashMaptimeMap = new HashMap(); /** * 记录当前时间为开始时间 * @param flag 作为标记存储 */ public long regist(int flag){ long startTime = SystemClock.elapsedRealtime(); timeMap.put(flag,startTime); return startTime; } /** * 获取当前时间与开始时间的差值 * @param flag 存储标记 * @return 如果返回-1,说明当前标记没有记录开始时间 */ public long getDifference(int flag){ if(timeMap.containsKey(flag)){ long endTime = SystemClock.elapsedRealtime(); long diff = endTime - timeMap.get(flag); return diff; } return -1; } /** * 自带log的开始记录 * @param flag * @param LogTag */ public long regist(int flag,String LogTag){ long time = regist(flag); LogUtils.SystemOut(TAG+LogTag," regist flag = " + flag + " time " +time); return time; } /** * 自带log的获取差值 * @param flag * @param LogTag * @return */ public long getDifference(int flag,String LogTag){ long time = getDifference(flag); LogUtils.SystemOut(TAG+LogTag," differece flag = " + flag + " time " +time); return time; }}