How to calculate difference between two dates in years…etc with Joda-Time

后端 未结 1 999
旧巷少年郎
旧巷少年郎 2020-12-01 16:24
import java.text.SimpleDateFormat;
import java.util.Date;
import org.joda.time.*;

public class Test {

  public static void main(String[] args) {

String dateStart          


        
相关标签:
1条回答
  • 2020-12-01 16:33

    Period gives you this out of the box.

    Period period = new Period(d1, d2);
    System.out.print(period.getYears() + " years, ");
    System.out.print(period.getMonths() + " months, ");
    // ...
    

    To prettify and get a little more control over the output, you can use a PeriodFormatterBuilder.

    0 讨论(0)
提交回复
热议问题