1、获取当前日期和昨天的日期 (格式yyyy-MM-dd)
@Test public void testJodaTime(){ LocalDate localDate = new LocalDate(); System.out.println(localDate.toString());//获取当前日期 2022-06-23 LocalDate yesterday = localDate.plusDays(-1);// 往前推一天,得到昨天的日期 System.out.println(yesterday.toString());// 2022-06-22 }
2、获取具体年、月、日
@Test public void testJodaTime(){ DateTime dateTime = new DateTime(); int day = dateTime.getDayOfMonth(); int month = dateTime.getMonthOfYear(); int year = dateTime.getYear(); System.out.println("今天是"+ day +"号"); System.out.println("现在是"+ month +"月"); System.out.println("现在是"+ year +"年"); }