Java实现 获取当前时间并且对日期进行加减计算

Java实现 获取当前时间并且对日期进行加减计算,第1张

Java实现 获取当前时间并且对日期进行加减计算

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));
    
  }

}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5695100.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存