java.time.LocalDateTime with()方法

java.time.LocalDateTime.with(TemporalAdjuster adjuster)方法返回此日期时间的调整副本。

1 语法

public LocalDateTime with(TemporalAdjuster adjuster)

2 参数

adjuster:要使用的调整器,而不是null。

3 返回值

一个LocalDateTime基于此进行调整,而不是null。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.time.LocalDateTime with()方法
 */
import java.time.LocalDateTime;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

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

      LocalDateTime date = LocalDateTime.parse("2017-01-03T10:15:30");
      LocalDateTime result = date.with(Month.JULY).with(TemporalAdjusters.lastDayOfMonth());
      System.out.println(result);  
   }
}

输出结果为:

2017-07-31T10:15:30

 

热门文章

优秀文章