標籤:print mini style ini port led bsp class system
1 package com.example.administrator.dayofmonth; 2 3 import java.text.SimpleDateFormat; 4 import java.util.Calendar; 5 import java.util.Date; 6 7 /** 8 * Created by 火龍裸先生 on 2017/4/11 0011. 9 */10 11 public class Number_Of_Days {12 13 /**14 * 擷取當月的 天數15 */16 public static int getCurrentMonthDay() {17 18 Calendar a = Calendar.getInstance();19 a.set(Calendar.DATE, 1);20 a.roll(Calendar.DATE, -1);21 int maxDate = a.get(Calendar.DATE);22 return maxDate;23 }24 25 /**26 * 根據 年、月 擷取對應的月份 的 天數27 */28 public static int getDaysByYearMonth(int year, int month) {29 30 Calendar a = Calendar.getInstance();31 a.set(Calendar.YEAR, year);32 a.set(Calendar.MONTH, month - 1);33 a.set(Calendar.DATE, 1);34 a.roll(Calendar.DATE, -1);35 int maxDate = a.get(Calendar.DATE);36 return maxDate;37 }38 39 /**40 * 根據日期 找到對應日期的 星期幾41 */42 public static String getDayOfWeekByDate(String date) {43 String dayOfweek = "-1";44 try {45 SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");46 Date myDate = myFormatter.parse(date);47 SimpleDateFormat formatter = new SimpleDateFormat("E");48 String str = formatter.format(myDate);49 dayOfweek = str;50 51 } catch (Exception e) {52 System.out.println("錯誤!");53 }54 return dayOfweek;55 }56 57 }
java擷取當月天數,指定年月的天數,指定日期擷取對應星期 .