Java获取当前年份、月份

import java.util.Calendar;

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;
    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("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);
  }
}
 
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);

 

posted @ 2013-03-04 10:40  微明Axel  阅读(804)  评论(0编辑  收藏  举报