标签:div out csdn blank ring mil imei second tps
应用场景:某些应用需要在特定的时间点更新数据
1 import java.text.DateFormat; 2 import java.text.SimpleDateFormat; 3 import java.util.Calendar; 4 5 public class RemainingTime { 6 public static void main(String[] args) { 7 Calendar calendar = Calendar.getInstance(); 8 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 9 System.out.println("当前时间:" + df.format(calendar.getTime())); 10 // 将日期调整为次日零时,即当前日期加一天,时、分、秒、毫秒都置零。 11 calendar.set(Calendar.MILLISECOND, 0); 12 calendar.set(Calendar.SECOND, 0); 13 calendar.set(Calendar.MINUTE, 0); 14 calendar.set(Calendar.HOUR_OF_DAY, 0); 15 calendar.add(Calendar.DAY_OF_MONTH, 1); 16 System.out.println("次日零时:" + df.format(calendar.getTime())); 17 System.out.println("从现在到凌晨还剩余:" + (calendar.getTimeInMillis() - System.currentTimeMillis()) / 1000 + " s"); 18 } 19 }
控制台输出:
当前时间:2019-07-08 16:17:50 次日零时:2019-07-09 00:00:00 从现在到凌晨还剩余:27729 s
标签:div out csdn blank ring mil imei second tps
原文地址:https://www.cnblogs.com/Satu/p/11151994.html