当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java TemporalAdjusters firstDayOfNextMonth()用法及代码示例


TemporalAdjusters类的firstDayOfNextMonth()方法用于返回“下个月的第一天” TemporalAdjuster对象,该对象返回一个设置为下个月第一天的新Date对象。

用法:

public static TemporalAdjuster firstDayOfNextMonth()

参数:此方法不接受任何内容。



返回值:此方法返回下个月的第一天调整器,不为null。

以下示例程序旨在说明TemporalAdjusters.firstDayOfNextMonth()方法:
程序1:

// Java program to demonstrate 
// TemporalAdjusters.firstDayOfNextMonth() 
  
import java.time.LocalDate; 
import java.time.temporal.TemporalAdjuster; 
import java.time.temporal.TemporalAdjusters; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // get TemporalAdjuster with first day 
        // of next month adjuster 
        TemporalAdjuster temporalAdjuster 
            = TemporalAdjusters.firstDayOfNextMonth(); 
  
        // using adjuster for local date time 
        LocalDate localDate 
            = LocalDate.of(2020, 05, 11); 
        LocalDate firstDayOfNextMonth 
            = localDate.with(temporalAdjuster); 
  
        // print 
        System.out.println("First day of next "
                           + "month for localdate "
                           + localDate + ":"
                           + firstDayOfNextMonth); 
    } 
}
输出:
First day of next month for localdate 2020-05-11:2020-06-01

程序2:

// Java program to demonstrate 
// TemporalAdjusters.firstDayOfNextMonth() method 
  
import java.time.LocalDate; 
import java.time.temporal.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // get TemporalAdjuster with first day 
        // of next month adjuster 
        TemporalAdjuster temporalAdjuster 
            = TemporalAdjusters 
                  .firstDayOfNextMonth(); 
  
        // using adjuster for local date-time 
        LocalDate localDate 
            = LocalDate.of(2010, 12, 29); 
        LocalDate firstDayOfNextMonth 
            = localDate.with(temporalAdjuster); 
  
        // print 
        System.out.println( 
            "First day of next "
            + "month for localdate "
            + localDate + ":"
            + firstDayOfNextMonth); 
    } 
}
输出:
First day of next month for localdate 2010-12-29:2011-01-01

参考文献:https://docs.oracle.com/javase/10/docs/api/java/time/format/TemporalAdjusters.html




相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 TemporalAdjusters firstDayOfNextMonth() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。