在线API参考:LocalTime (Java Platform SE 8 )
方法介绍
方法1 | 方法1 | 说明 |
plusYears(long years) | minusYears(long years) | 返回增加/减少了年数的副本 |
plusMonths(long months) | minusMonths(long months) | 返回增加/减少了月数的副本 |
plusWeeks(long weeks) | minusWeeks(long weeks) | 返回增加/减少了周数的副本 |
plusDays(long days) | minusDays(long days) | 返回增加/减少了天数的副本 |
plusHours(long hours) | minusHours(long hours) | 返回增加/减少了小时数的副本 |
plusSeconds(long seconds) | minusMinutes(long minutes) | 返回增加/减少了分钟数的副本 |
plusSeconds(long seconds) | minusSeconds(long seconds) | 返回增加/减少了秒数的副本 |
plusNanos(long nanos) | minusNanos(long nanos) | 返回增加/减少了纳秒数的副本 |
public class BaseTest {public static void main(String[] args) throws ParseException {LocalDateTime localTime = LocalDateTime.now();System.out.println("当前时间: " + localTime);System.out.println("增加1年:" + localTime.plusYears(1));System.out.println("增加1个月:" + localTime.plusMonths(1));System.out.println("增加1周:" + localTime.plusWeeks(1));System.out.println("增加1天:" + localTime.plusDays(1));System.out.println("增加1小时: " + localTime.plusHours(1));System.out.println("增加30分钟: " + localTime.plusMinutes(30));System.out.println("增加30秒: " + localTime.plusSeconds(30));System.out.println("增加10000纳秒:" + localTime.plusNanos(10000));System.out.println("减少1年:" + localTime.minusYears(1));System.out.println("减少1个月:" + localTime.minusMonths(1));System.out.println("减少1周:" + localTime.minusWeeks(1));System.out.println("减少1天:" + localTime.minusDays(1));System.out.println("减少1小时:" + localTime.minusHours(1));System.out.println("减少30分钟:" + localTime.minusMinutes(30));System.out.println("减少30秒: " + localTime.minusSeconds(30));System.out.println("减少10000纳秒:" + localTime.minusNanos(10000));}
}