java 24小时倒计时案例
Posted xh_Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 24小时倒计时案例相关的知识,希望对你有一定的参考价值。
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
以上是关于java 24小时倒计时案例的主要内容,如果未能解决你的问题,请参考以下文章
24 小时倒计时计时器,带有三个单独的文本视图,分别显示小时、分钟、秒