1234567891011121314151617181920212223242526272829 |
- package com.alvin.util;
- class StopWatch {
- private String name = "";
- private long startTime;
- public StopWatch() {
- startTime = System.currentTimeMillis();
- }
- public StopWatch(String name) {
- this();
- this.name = name;
- }
- public String stop() {
- long endTime = System.currentTimeMillis();
- long spendTime = endTime - this.startTime;
- String s = DateUtil.formatTime(spendTime);
- System.out.println(this.name + " 用时:" + s);
- return s;
- }
- public static void main(String[] args) throws InterruptedException {
- StopWatch stopWatch = new StopWatch("A");
- Thread.sleep(100);
- stopWatch.stop();
- }
- }
|