如何根据在Java中提供的天数计算下一个日期(天、月和年)?

huangapple go评论60阅读模式
英文:

How to calculate next date(days months and year) based on provided number of days in java?

问题

我正在尝试根据提供的天数计算基准日期(即当前日期或任何特定日期)之后的新日期。
Linux Shell 可以通过以下方式实现:

date -d "2020-10-19 +30 days"

其中,2020-10-19 是基准日期,30 表示在基准日期之后的新日期天数。

英文:

Iam trying to calculate new date based on provided no. of days to base date(i.e current date or any specific date).
Linux shell can do by
date -d "2020-10-19 30 days"

2020-10-19 is base date
30 is new date after 30 days.

答案1

得分: 0

import java.time.LocalDate;

public class Main {

    public static void main(String[] args) {
        final LocalDate now = LocalDate.now();
        final LocalDate nowPlus30Days = now.plusDays(30);
        System.out.println(nowPlus30Days);
    }
}
英文:
import java.time.LocalDate;

public class Main {

    public static void main(String[] args) {
        final LocalDate now = LocalDate.now();
        final LocalDate nowPlus30Days = now.plusDays(30);
        System.out.println(nowPlus30Days);
    }
}

huangapple
  • 本文由 发表于 2020年10月19日 15:45:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/64423096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定