JAVA【倒计时1分钟】


第一种方法:


import java.text.SimpleDateFormat;
import java.util.Date;


public class TimesABCD {

public static void main(String[] args) {
long ll;
long l = System.currentTimeMillis();
ll = l;
while (true) {
System.out.println("倒计时开始!");
System.out.println(new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(l)));
l = System.currentTimeMillis();
long d = l - ll;
if (d % 1000 == 0)
System.out.println(new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(l)));
if (d > 60000) {
System.out.println("倒计时结束!");
break;
}


}


}


}


【JAVA【倒计时1分钟】】第二种方法:


public class TimesABCD {


public static void countDown(int seconds) {
System.err.println("倒计时" + seconds + "秒,倒计时开始:");
int i = seconds;
while (i > 0) {
System.err.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i--;
}
System.err.println(i);
System.err.println("倒计时结束");
}


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
countDown(60); // 倒计时1分钟
}
}

    推荐阅读