- //sleep 模拟网络延迟:
- public class hh implements Runnable {
- public static void main(String[]args) throws InterruptedException
- {
- Date date=new Date(System.currentTimeMillis()+1000*10);// 当前时间加 10 秒
- long endTime=date.getTime();
- while(true)
- {
- System.out.println(new SimpleDateFormat("mm:ss").format(date));// 以分: 秒的形式输出
- Thread.sleep(1000);
- date=new Date(date.getTime()-1000);
- if(endTime-1000*10>date.getTime())
- {
- break;
- }
- }
- }
- public static void test() throws InterruptedException
- {
- int num=10;
- while(true)
- {
- Thread.sleep(1000);
- System.out.println(num--);
- }
- }
- }
来源: http://www.bubuko.com/infodetail-3148401.html