为了满足更多的需求,JDK 8中新增了一个java.time包,在该包下包含了更多的日期和时间操作类

//类名             功能描述
//Clock        用于获取指定时区的当前日期、时间。
//DayOfWeek    枚举类,定义了一周七天周一到周日的枚举值
//Duration     表示持续时间。该类提供的ofXxx()方法用于获取指定的时间的小时、分钟、秒数等。
/*Instant      表示一个具体时刻,可以精确到纳秒。
该类提供了静态的now()方法来获取当前时刻,提供了静态的now(Clock clock)方法来获取clock对应的时刻。
同时还提供了一系列的plusXxx()方法来获取当前时刻基础上加上一段时间,以及一系列的minusXxx()方法在当前时刻基础上减去一段时间。*/
/*LocalDate    表示不带时区的日期,如2018-01-27。
该类提供了静态的now()方法来获取当前日期,提供了静态的now(Clock clock)方法来获取clock对应的日期。
同时还提供了一系列的plusXxx()方法在当前年份基础上加上几年、几月、几日等,以及一系列的minusXxx()方法在当前年份基础上减去几年、几月、几日等。*/
/*LocalTime    表示不带时区的时间,如14:49:20。
该类提供了静态的now()方法来获取当前时间,提供了静态的now(Clock clock)方法来获取clock对应的时间。
同时还提供了一系列的plusXxx()方法在当前年份基础上加上几小时、几分、几秒等,以及一系列的minusXxx()方法在当前年份基础上减去几小时、几分、几秒等。*/
/*LocalDateTime    表示不带时区的日期、时间。该类提供了静态的now()方法来获取当前日期、时间,
提供了静态的now(Clock clock)方法来获取clock对应的日期、时间。
同时还提供了一系列的plusXxx()方法在当前年份基础上加上几年、几月、几日、几小时、几分、几秒等,
以及一系列的minusXxx()方法在当前年份基础上减去几年、几月、几日、几小时、几分、几秒等。*/
//Month    枚举类,定义了一月到十二月的枚举值
//MonthDay   表示月日,如--01-27。该类提供了静态的now()方法来获取当前月日,提供了静态的now(Clock clock)方法来获取clock对应的月日。
package changYongLei;

import java.time.*;

public class ShiJianRiQiLei_DuoZhongFangFa {
   public static void main(String[] args) {
    //1.Clock的使用
    System.out.println("(1)============================================");
    Clock c = Clock.systemUTC();
    System.out.println("获取UTC时区转换的当前时间:"+c.instant());
    System.out.println("获取UTC时区转换的毫秒数:"+c.millis());
    //2.Duration的使用
    System.out.println("(2)============================================");
    Duration d = Duration.ofDays(1);
    System.out.println("一天等于"+d.toHours()+"小时");
    System.out.println("一天等于"+d.toMinutes()+"分钟");
    System.out.println("一天等于"+d.toMillis()+"秒");
    //3.Instant的使用
    System.out.println("(3)============================================");
    Instant st = Instant.now();
    System.out.println("获取UTC时区的当前时间为:"+st);
    System.out.println("当前时间一小时后的时间为:"+st.plusSeconds(3600));//以秒进行增加,看增加的单位看plus后的单位表示什么
    System.out.println("当前时间一小时前的时间为:"+st.minusSeconds(3600));
    //4.LocalDate的使用
    System.out.println("(4)============================================");
    LocalDate date = LocalDate.now();
    System.out.println("从默认时区的系统时钟获得当前日期:"+date);
    //5.LocalTime的使用
    System.out.println("(5)============================================");
    LocalTime time = LocalTime .now();
    System.out.println("从默认时区的系统时钟获得当前时间:"+time);
    //6.LocalDateTime
    System.out.println("(6)============================================");
    LocalDateTime  dateTime = LocalDateTime.now();
    System.out.println("从默认时区的系统时钟获取日期、时间:"+dateTime);
    LocalDateTime  dateTime2 = dateTime.plusDays(1).plusHours(3).plusMinutes(30);
    System.out.println("当前的日期、时间加上1天3小时30分钟之后:"+dateTime2);
    //7.Year、YearMonth、MonthDay的使用
    System.out.println("(7)============================================");
    Year y = Year.now();
    System.out.println("当前年份为:"+y);
    YearMonth ym = YearMonth.now();
    System.out.println("当前年月为:"+ym);
    MonthDay md = MonthDay.now();
    System.out.println("当前月日为:"+md);
    //8.获取系统默认时区
    System.out.println("(8)============================================");
    ZoneId z = ZoneId.systemDefault();
    System.out.println("当前系统默认时区为:"+z);
   }
}

java data日期减去分钟 java当前日期减去一月_当前日期