2014-03-31 114 views
0
import java.time.LocalDate; 
import java.time.Period; 

    public class DateDiff { 

     public static void main(String[] args) { 
      /** The date at the end of the last century */ 
      LocalDate endofCentury = LocalDate.of(2000, 12, 31); 
      LocalDate now = LocalDate.now(); 

      Period diff = Period.between(endofCentury, now); 

      System.out.printf("The 21st century (up to %s) is %s old%n", now, diff); 
      System.out.printf("The 21st century is %d years, %d months and %d days old", 
        diff.getYears(), diff.getMonths(), diff.getDays()); 
     } 
    } 

本地日期沒有被發現我缺少一個導入指令導入失敗的java.time.LocalDate

+3

您使用的是Java 8嗎? –

回答

9

檢查,如果你正在使用JDK 8
我想你是不是,這就是你的問題。