Use the calendar class to get the year, month and day
•
Java
import java.util.Calendar;
public class time_Calender {
public static void main(String[] args) {
Calendar cal=Calendar.getInstance();
int day=cal.get(Calendar.DATE);
int month=cal.get(Calendar.MONTH)+1;
int year=cal.get(Calendar.YEAR);
int dow=cal.get(Calendar.DAY_OF_WEEK);
int dom=cal.get(Calendar.DAY_OF_MONTH);
int doy=cal.get(Calendar.DAY_OF_YEAR);
System.out.println("当前时间:"+cal.getTime());
System.out.println("日期:"+day);
System.out.println("月份:"+month);
System.out.println("年:"+year);
System.out.println("一周的第几天:"+dow); //星期日为一周的第一天输出为 1,星期一输出为 2,以此类推
System.out.println("一月的第几天:"+dom);
System.out.println("一年的第几天:"+doy);
}
}
The output result is:
Current time: fri May 29 15:19:24 CST 2020 date: 29 month: 5 years: the day of 2020 week: the day of June: the day of 29 year: 150
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
