java定时器控制时间打印

 1 public class test2 {
 2 public static void main(String []args){
 3 Timer timer=new Timer();
 4 timer.schedule(new TimerTask(){
 5 
 6 
 7 @Override
 8 public void run() {
 9 // TODO Auto-generated method stub
10 SimpleDateFormat sdf = new SimpleDateFormat("yyyyyyyy-MM-dd HH(hh):mm:ss S E D F w W a k K z");  
11        long times = System.currentTimeMillis();
12        Date date = new Date(times);  
13        String tim = sdf.format(date);  
14 System.out.println(times+"-----------"+tim);
15 }
16 
17 }, 0,10);
18 }
19 
20 }
原文地址:https://www.cnblogs.com/tnsay/p/5752715.html