package 日期;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
class Threadmady implements Runnable{
@Override
public void run() {
int time;
System.out.println("每隔5秒钟输出当前的日期-时间:");
try {
//for(time=0;time<3;time++){
//int j=0;
for(time=0;time<5;time++){
System.out.println("5秒倒计时第"+(time+1)+"次");
Date date=new Date();
SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str=sim.format(date);
//if(j==0){
Thread.sleep(5000);
System.out.println(str);
//}
}
// }
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class TextDame {
public static void main(String[] args) {
Threadmady my=new Threadmady();//初始化对象
Thread t=new Thread(my,"线程");
t.start();
}
}