package liu.dh.java;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Timer;
import java.util.TimerTask;
public class Time2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Timer timer = new Timer();
timer.schedule(new Times1(), 0);
}
}
class Times1 extends TimerTask{
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SS");
public void run(){
long t1 = System.currentTimeMillis();
while (true) {
//System.out.println(df.format(System.currentTimeMillis()));
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(df.format(System.currentTimeMillis()-t1));
System.out.println(System.currentTimeMillis()-t1);
}
}
}
|
|