码迷,mamicode.com
首页 > 编程语言 > 详细

java 24小时倒计时案例

时间:2017-11-08 15:58:38      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:div   .com   detail   interrupt   read   sdn   java   sys   html   

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小时倒计时案例

标签:div   .com   detail   interrupt   read   sdn   java   sys   html   

原文地址:http://www.cnblogs.com/YLQBL/p/7804271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!