导入java.time.LocalDate失败

时间:2014-03-31 11:12:50

标签: java date java-time

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

我没有找到本地日期我错过了导入指令

1 个答案:

答案 0 :(得分:9)

检查您是否使用JDK 8 我想你不是,那是你的问题。