1、Date类的使用
Date date = new Date ( ) ;
SimpleDateFormat dateFormat = new SimpleDateFormat ( ) ;
dateFormat. applyPattern ( "yyyy'年'MM'月'dd'日'" ) ;
String formatDate = dateFormat. format ( date) ;
System . out. println ( formatDate) ;
2、Calendar类的使用
Calendar calendar = Calendar . getInstance ( ) ;
int year = calendar. get ( Calendar . YEAR) ;
int month = calendar. get ( Calendar . MONTH) + 1 ;
int dayOfWeek = calendar. get ( Calendar . DATE) ;
int hour12 = calendar. get ( Calendar . HOUR) ;
int hour24 = calendar. get ( Calendar . HOUR_OF_DAY) ;
int minute = calendar. get ( Calendar . MINUTE) ;
int second = calendar. get ( Calendar . SECOND) ;
int milliSecond = calendar. get ( Calendar . MILLISECOND) ;
System . out. println ( year+ "年" + month+ "月" + dayOfWeek+ "日" + hour24+ "时" + minute+ "分" + second+ "秒" + milliSecond+ "毫秒" ) ;
SimpleDateFormat dateFormat1 = new SimpleDateFormat ( "yyyy:MM:dd" ) ;
Date date1 = dateFormat1. parse ( "2012:12:01" ) ;
calendar. setFirstDayOfWeek ( Calendar . MONDAY) ;
calendar. setTime ( date1) ;
int dayOfWeek1 = calendar. get ( Calendar . DAY_OF_WEEK) - 1 ;
int dayOfMonth = calendar. get ( Calendar . DAY_OF_MONTH) ;
int dayOfYear = calendar. get ( Calendar . DAY_OF_YEAR) ;
int weekOFMonth = calendar. get ( Calendar . WEEK_OF_MONTH) ;
int weekOfYear = calendar. get ( Calendar . WEEK_OF_YEAR) ;
System . out. println ( "dayOfWeek: " + dayOfWeek1) ;
System . out. println ( "dayOfMonth: " + dayOfMonth) ;
System . out. println ( "dayOfYear: " + dayOfYear) ;
System . out. println ( "weekOFMonth: " + weekOFMonth) ;
System . out. println ( "weekOfYear: " + weekOfYear) ;