Get milliseconds until midnight

前端 未结 6 1758
一生所求
一生所求 2020-12-06 04:20

I\'m creating an Android widget that I want to update every night at midnight. I am using an AlarmManager and I need to find out how many milliseconds are left

6条回答
  •  無奈伤痛
    2020-12-06 04:38

    Using the following way, there is no need to worry about setting DAY_OF_MONTH.

        long msInDay = 86400000;
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
    
        System.out.print(msInDay - (System.currentTimeMillis() - c.getTimeInMillis()));
    

提交回复
热议问题