import java.util.Calendar; import java.util.Date; public class Daojishi { static String Countdown=""; public static void main(String[] args) { //开启倒计时 time2(); System.out.println("Countdown="+Countdown); } /** * 倒计时,设定时间戳 */ private static void time2() { Calendar c = Calendar.getInstance(); c.set(c.get(Calendar.YEAR), (c.get(Calendar.MONTH) + 1), c.get(Calendar.DAY_OF_MONTH)+1, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));// 注意月份的设置,0-11表示1-12月 long endTime = c.getTimeInMillis(); Date date = new Date(); long startTime = date.getTime(); long midTime = (endTime - startTime) / 1000; while (midTime > 0) { midTime--; long hh = midTime / 60 / 60 % 60; long mm = midTime / 60 % 60; long ss = midTime % 60; System.out.println("还剩" + hh + "小时" + mm + "分钟" + ss + "秒"); System.out.println( hh+""+mm+""+ss+""); Countdown=hh+""+mm+""+ss+""; try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
参考:
http://www.cnblogs.com/heizai002/p/6862625.html
http://blog.csdn.net/kookob/article/details/6885383