欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java获取12个月前的月初日期

程序员文章站 2022-05-15 09:49:03
...
   public class FirstDayOfLastTwelveMonth {
          public static void main(String[] args){
                DateTimeFormatter formatter = DateTimeFormatter.forPattern("yyyyMMdd");
                DateTime dateTime = formatter.parseDateTime("20151231");
                
                Period period = new Period(0,11,0,0,0,0,0,0);
                DateTime theDate = dateTime.minus(period);
                DateTime firstDay = theDate.withField(DateTimeFormatter.dayOfMonth, 1)

                System.out.println(formatter.print(firstDay));
          }
   }