Java实现 获取当前时间,并且对日期进行加减一天、一周以及一年的计算,结果图如下:
具体代码如下:
import java.time.LocalDate;
public class DateTest10 {
public static void main(String[] args) {
LocalDate now = LocalDate.now();
System.out.println("当前:" + now.toString());
System.out.println("加法运算");
System.out.println("加1天:" + now.plusDays(1));
System.out.println("加1周:" + now.plusWeeks(1));
System.out.println("加1月:" + now.plusMonths(1));
System.out.println("加1年:" + now.plusYears(1));
System.out.println("减法运算");
System.out.println("减1天:" + now.minusDays(1));
System.out.println("减1周:" + now.minusWeeks(1));
System.out.println("减1月:" + now.minusMonths(1));
System.out.println("减1年:" + now.minusYears(1));
}
}