JAVA实现简单的时间刷新使用线程
1 package 多线程练习; 2 3 import java.text.SimpleDateFormat; 4 import java.util.Date; 5 6 public class 时间计时器 { 7 public static void main(String[] args) throws InterruptedException { 8 while (true) { 9 System.out.println(getDateTime()); 10 Thread.sleep(1000); 11 } 12 } 13 14 public static String getDateTime() { 15 String format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss").format(new Date(System.currentTimeMillis())); 16 return format; 17 } 18 }