public static void main(string args) {
calendar cal = calendar.getinstance();
cal.settime(new date());
//當前年
int year = cal.get(calendar.year);
//當前月
int month = (cal.get(calendar.month))+1;
//當前月的第幾天:即當前日
int day_of_month = cal.get(calendar.day_of_month);
//當前時:hour_of_day-24小時制;hour-12小時制
int hour = cal.get(calendar.hour_of_day);
//當前分
int minute = cal.get(calendar.minute);
//當前秒
int second = cal.get(calendar.second);
//0-上午;1-下午
int ampm = cal.get(calendar.am_pm);
//當前年的第幾周
int week_of_year = cal.get(calendar.week_of_year);
//當前月的第幾周
int week_of_month = cal.get(calendar.week_of_month);
//當前年的第幾天
int day_of_year = cal.get(calendar.day_of_year);
system.out.println("當前年==/t"+year);
system.out.println("當前月==/t"+month);
system.out.println("當前月的第幾天:即當前日===/t"+day_of_month);
system.out.println("當前時hour_of_day-24小時制;hour-12小時制===/t"+hour);
system.out.println("當前分===/t"+minute);
system.out.println("當前分===/t"+second);
system.out.println("0-上午;1-下午==/t"+ampm);
system.out.println("當前年的第幾周/t"+week_of_year);
system.out.println("當前月的第幾周/t"+week_of_month);
system.out.println("當前年的第幾天/t"+day_of_year);
calendar cal1 = calendar.getinstance();
date date=new date();
cal1.settime(date);
calendar cal2 = calendar.getinstance();
cal2.settime(date);
system.out.println(cal1.get(calendar.year)-cal2.get(calendar.year));
system.out.println(cal1.get(calendar.month)-cal2.get(calendar.month));
system.out.println(cal1.get(calendar.month));
system.out.println(cal1.get(calendar.year));
system.out.println(cal1.get(calendar.month)-cal2.get(calendar.year));
calendar 類的使用
下週,或者下個月 calendar calendar calendar.getinstance calendar.set calendar.year,2013 設定年份 calendar.set calendar.month,10 設定月份,顯示的比當前多乙個月 calendar.set calen...
日曆類Calendar的使用
可以通過calendar獲得日曆物件,進而獲取日期和具體時間 calendar instance calendar.getinstance int year instance.get calendar.year int month instance.get calendar.month int da...
使用Calendar需要注意clear
date是前台傳的值,格式為2014 01 01的形式 如下的 是去date日期當月的最大天數日期 int month integer.parseint date.substring 5,7 取天數 int year integer.parseint date.substring 0,4 取年份 d...