Get the 0 o'clock time of the day and the 0 o'clock time tomorrow in Java

Get the 0 o'clock time of the day and the 0 o'clock time tomorrow in Java

	DateFormat format = new SimpleDateFormat("yyyy-MM-dd");

	Calendar calendar = Calendar.getInstance();
	calendar.setTime(new Date());
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	Date today = calendar.getTime();
	calendar.set(DAY_OF_MONTH,calendar.get(DAY_OF_MONTH) +1);
	Date tomorrow =calendar.getTime();

	String todayString = format.format(today);
	String tomorrowString = format.format(tomorrow);
	System.out.println("今天是:" + todayString);
	System.out.println("明天是:" + tomorrowString);

Output:
Insert picture description here

Guess you like

Origin blog.csdn.net/JAYU_37/article/details/109220404