Java month firstMonthOfQuarter()方法

来源:这里教程网 时间:2026-02-17 20:57:42 作者:

Java month firstMonthOfQuarter()方法

firstMonthOfQuarter() 是Month ENUM的一个内置方法,用于获取本季度对应的第一个月。季度的定义是将一年分为4组。

第1组:1月、2月、3月第2组:4月、5月、6月第3组:7月、8月、9月第4组:10月、11月、12月

语法:

public int firstMonthOfQuarter()

参数 :该方法不接受任何参数。

返回值 :该方法返回本季度第一个月所对应的月份。

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

程序1 :

import java.time.*;import java.time.Month;import java.time.temporal.Temporal;  class DayOfWeekExample {    public static void main(String[] args)    {        // Set the month to february, 1st Quarter        Month month = Month.of(2);          // Get the first month of this quarter        System.out.println(month.firstMonthOfQuarter());    }}

输出。

JANUARY

程序2 :

import java.time.*;import java.time.Month;import java.time.temporal.Temporal;  class DayOfWeekExample {    public static void main(String[] args)    {        // Set the month to JUNE, 2nd Quarter        Month month = Month.of(6);          // Get the first month of this quarter        System.out.println(month.firstMonthOfQuarter());    }}

输出。

APRIL

参考资料 : https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#firstMonthOfQuarter-

相关推荐