在java中获取时间都需要日期函数,下面就让我们来看一下如何使用。

首先使用日历类,然后使用它的方法获取当前月份
package test;
import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Calendar cal=Calendar.getInstance();//使用日历类
int month=cal.get(Calendar.MONTH)+1;//得到月,因为从0开始的,所以要加1
System.out.println("当前月份:"+month);
}
}结果:
当前月份:5











