Java Calendar獲取時間的月和日 周

2021-06-27 22:02:08 字數 773 閱讀 1200

calendar cal = calendar.getinstance();

// 當前年

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);

Java Calendar獲取年 月 日 時間

calendar c calendar.getinstance timezone.gettimezone gmt 08 00 獲取東八區時間 int year c.get calendar.year 獲取年 int month c.get calendar.month 1 獲取月份,0表示1月份 i...

java Calendar學習筆記

calendar 與 date 的轉換非常簡單 calendar calendar calendar.getinstance 從乙個 calendar 物件中獲取 date 物件 date date calendar.gettime 將 date 物件反應到乙個 calendar 物件中,calen...

Java Calendar使用總結

dateformat sdf new dateformat yyyy mm dd hh mm ss sss 初始化 calendar cal calendar.getinstance int year cal.get calendar.year 年 int month cal.get calenda...