I just finished writing the code, it was expelled from the ........
Give it the code for later use:
package mydemo; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class ThreeDay { public static void main(String[] args) { getToday (); getYesterday(); getTomorrow(); } /** * Get today's date */ public static void getToday() { //SimpleDateFormat smdate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); SimpleDateFormat smdate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); String date = smdate.format(new Date()); System.out.println(date); } /** * Get yesterday's date */ public static void getYesterday() { SimpleDateFormat smdate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); Calendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); calendar.add(calendar.DATE, -1); String date = smdate.format(calendar.getTime()); System.out.println(date); } /** * Get tomorrow's date */ public static void getTomorrow() { SimpleDateFormat smdate = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); Calendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); calendar.add(calendar.DATE, 1); String date = smdate.format(calendar.getTime()); System.out.println(date); } }
result: