java.time.Period normalized()方法

java.time.Period.normalized()方法返回此期间的副本,其中年份和月份已标准化。

1 语法

public Period normalized()

2 参数

3 返回值

一个基于此Period的期间,超额月份标准化为年,不为null。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.time.Period normalized()方法
 */
import java.time.Period;

public class PeriodDemo {
   public static void main(String[] args) {

      Period period = Period.of(1,15,2);
      System.out.println("Years: " + period.getYears() 
         + ", Months: " + period.getMonths()
         +", Days: " + period.getDays());
      Period period1 = period.normalized();
      System.out.println("Years: " + period1.getYears() 
         + ", Months: " + period1.getMonths()
         +", Days: " + period1.getDays());
   }
}

输出结果为:

Years: 1, Months: 15, Days: 2
Years: 2, Months: 3, Days: 2

 

热门文章

优秀文章