java获取当前年份
人气:0java获取当前年份
操作方法
- 01
java 获取当前年份 月份 日期import java.util.Calendar;
- 02
public class Main {public static void main(String[] args) {Calendar cal = Calendar.getInstance();int day = cal.get(Calendar.DATE);int month = cal.get(Calendar.MONTH) + 1;
- 03
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);
- 04
System.out.println("Current Date: " + cal.getTime());System.out.println("Day: " + day);System.out.println("Month: " + month);System.out.println("Year: " + year);System.out.println("Day of Week: " + dow);System.out.println("Day of Month: " + dom);System.out.println("Day of Year: " + doy);}}
- 05
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");java.util.Date currTime = new java.util.Date();int year = currTime.getYear();//年int month = currTime.getMonth()+1;//月int week = currTime.getDay(); //星期几int day = currTime.getDate();//日String curTime = formatter.format(currTime);
加载全部内容