📜  Java中的月份减法()方法

📅  最后修改于: 2022-05-13 01:55:39.569000             🧑  作者: Mango

Java中的月份减法()方法

minus()方法是 Month ENUM 的内置方法,用于获取当前月份前一个月的特定月份数。也就是说,此方法返回从本月开始的指定月数之前的月份。

语法

public Month minus(long months)

参数:此方法接受单个参数months ,表示月数。

返回值:此方法返回本月指定月数之前的月份

下面的程序说明了上述方法:

程序 1

import java.time.*;
import java.time.Month;
import java.time.temporal.ChronoField;
  
class monthEnum {
    public static void main(String[] args)
    {
        // Create a month instance
        Month month = Month.FEBRUARY;
  
        // Print the month present 1
        // month before feb
        System.out.println(month.minus(1));
    }
}
输出:
JANUARY

方案二

import java.time.*;
import java.time.Month;
import java.time.temporal.ChronoField;
  
class monthEnum {
    public static void main(String[] args)
    {
        // Create a month instance
        Month month = Month.APRIL;
  
        // Print the month present 1
        // month before feb
        System.out.println(month.minus(2));
    }
}
输出:
FEBRUARY

参考:https: Java/time/Month.html#minus-long-