import java.util.Calendar;
import java.util.Locale;
public class DateTest {
public static void main(String[] args0) {
Calendar cal = Calendar.getInstance();
//cal.setTime(new Date(2017,4,12,14,40,18));
// Calendar cal = Calendar.getInstance();
//获取当前日期是第几周
Locale.setDefault(Locale.CHINA);
String year = String.valueOf(cal.get(Calendar.YEAR));
System.out.println(“当前是”+year+“年”);
//Java中的月份遵循了罗马历中的规则:当时一年中的月份数量是不固定的,第一个月是JANUARY。
// 而Java中Calendar.MONTH返回的数值其实是当前月距离第一个月有多少个月份的数值,JANUARY在Java中返回“0”,所以我们需要+1。
String MONTH = String.valueOf(cal.get(Calendar.MONTH)+1);
System.out.println(“当前月第”+MONTH+“个月”);
//获取当前日期是几号
String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
System.out.println(“当前日期是”+day+“号”);
String DAY_OF_YEAR = String.valueOf(cal.get(Calendar.DAY_OF_YEAR));
System.out.println(“今天是今年第”+DAY_OF_YEAR+“天”);
String DAY_OF_WEEK_IN_MONTH = String.valueOf(cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println(“当前月第”+DAY_OF_WEEK_IN_MONTH+“周”);
//Java中Calendar.DAY_OF_WEEK其实表示:一周中的第几天,所以他会受到 第一天是星期几 的影响。
String DAY_OF_WEEK = String.valueOf(cal.get(Calendar.DAY_OF_WEEK)-1);
System.out.println(“今天周”+DAY_OF_WEEK);
//AM_PM=0,上午;AM_PM=1,下午
String AM_PM = String.valueOf(cal.get(Calendar.AM_PM));
if(“0”.equals(AM_PM)){
System.out.println(“AM_PM=”+AM_PM+",当前时刻为上午");
}else{
System.out.println(“AM_PM=”+AM_PM+",当前时刻为下午");
}
String HOUR_OF_DAY = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
System.out.println(“当前时间”+HOUR_OF_DAY+“时”);
}
}