开发者

Countdown clock in android

开发者 https://www.devze.com 2023-02-02 18:36 出处:网络
I need to dis开发者_如何学运维play a countdown clock, I calculated the difference between dates in miliseconds, how can I convert this to countdown clock, i.e \"20days 12hrs 12min remaining\"? I can g

I need to dis开发者_如何学运维play a countdown clock, I calculated the difference between dates in miliseconds, how can I convert this to countdown clock, i.e "20days 12hrs 12min remaining"? I can get hrs remaining.

(mili / 24 * 60 * 60 * 1000)

But This is the total hours remaining how can i convert this to 0-24 hrs 0-60 min format ?


        //setting time
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal2.set(Calendar.DATE, 31);
        cal2.set(Calendar.HOUR_OF_DAY, 1);
        cal2.set(Calendar.MINUTE, 50);
        //printing dates

        System.out.println("Date1"+ cal1.getTime());
        System.out.println("Date1"+ cal2.getTime());
        long diffInMillis = cal2.getTimeInMillis() - cal1.getTimeInMillis();

        System.out.println("Diff In Millis : " + diffInMillis);

        int hour  = (int)(diffInMillis/(60.0 * 1000 * 60 ));
        int min  = (int)((diffInMillis - (hour *60.0 *1000 *60))/(60.0*1000));

        System.out.println("Diff In HH:MM: " + hour + ":" + min );


You could use the standard java.util.Calendar class.

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(yourTime);
int hour = cal.get(Calendar.HOURS_IN_DAYS);
0

精彩评论

暂无评论...
验证码 换一张
取 消