package jqqd.Example;

/**
 * @(#)Beijing2008.java
 *
 *
 * @author
 * @version 1.00 2008/5/4
 */


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


public class Beijing2008 {
	public static void main(String[] args) throws InterruptedException{
        long t=1000l;
        System.out.println("                ----------北京2008奥运会倒计时----------");
		System.out.println ();
		Calendar cal=GregorianCalendar.getInstance();
		cal.set(2008,7,8,0,0,0);
		long time=cal.getTime().getTime();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss");
		long days  =0l,days_ =0l;
		long hours =0l,hours_=0l;
		long mins  =0l,mins_ =0l;
		long secs  =0l;
		Date now=null;
		for(;;){
            now=new Date();
			days  =(time-now.getTime())/(24*60*60*1000);
			days_ =(time-now.getTime())%(24*60*60*1000);
			hours =days_/(60*60*1000);
			hours_=days_%(60*60*1000);
			mins  =hours_/(60*1000);
			mins_ =hours_%(60*1000);
			secs  =mins_/(1000);
			cal.set(0,0,0,(int)hours,(int)mins,(int)(secs+1));
			System.out.print('\r'+"现在是 "+(sdf.format(now))
				+" 距离北京奥运会还剩 "+days+" 天 "
				+(cal.getTime().toString().substring(11,19)));
			Thread.sleep(t);
		}
	}
}

 

评论
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论