|
|
|
@ -64,3 +64,89 @@ eyJhbGciOiJIUzUxMiJ9.eyJhdWQiOiJCRDg0REQ0MkE3MjM0QjA1QjBDNUQxMTYxNjEzMkFDNCIsImp |
|
|
|
20、[Java中的Set](https://blog.csdn.net/qq_46209845/article/details/120220136) |
|
|
|
|
|
|
|
21、[BigDecimal加减乘除计算](https://www.jianshu.com/p/683b2406342f) |
|
|
|
|
|
|
|
|
|
|
|
###知识点收集: |
|
|
|
首先使用Calendar calendar = Calendar.getInstance();//获取Calendar |
|
|
|
|
|
|
|
获取当前时间:calendar.getTime(); |
|
|
|
|
|
|
|
设置时间:calendar.setTime(new Date());//可以给calendar设置一个日期 示例给了一个new Date() |
|
|
|
|
|
|
|
calendar中add和set的区别:set 表示直接设值 不考虑原来的时间值;add 表示在原有的基础上进行加减value |
|
|
|
|
|
|
|
//当前年 |
|
|
|
|
|
|
|
int year = cal.get(Calendar.YEAR); |
|
|
|
|
|
|
|
//当前月 Calendar.MONTH从0开始 |
|
|
|
|
|
|
|
int month = (cal.get(Calendar.MONTH))+1; |
|
|
|
|
|
|
|
//当前月的第几天:即当前日 |
|
|
|
|
|
|
|
int day_of_month = cal.get(Calendar.DAY_OF_MONTH); |
|
|
|
|
|
|
|
//Calendar.DAY_OF_MONTH 和 Calendar.DATE 是等价的 |
|
|
|
|
|
|
|
int date = cal.get(Calendar.DATE); |
|
|
|
|
|
|
|
//当前时:HOUR_OF_DAY-24小时制 |
|
|
|
|
|
|
|
int hour24 = cal.get(Calendar.HOUR_OF_DAY); |
|
|
|
|
|
|
|
//HOUR-12小时制 |
|
|
|
|
|
|
|
int hour12 = cal.get(Calendar.HOUR); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//当前分 |
|
|
|
|
|
|
|
int minute = cal.get(Calendar.MINUTE); |
|
|
|
|
|
|
|
//当前秒 |
|
|
|
|
|
|
|
int second = cal.get(Calendar.SECOND); |
|
|
|
|
|
|
|
// 星期几 Calendar.DAY_OF_WEEK用数字(1~7)表示(星期日~星期六) |
|
|
|
|
|
|
|
int day_of_week = cal.get(Calendar.DAY_OF_WEEK)-1; |
|
|
|
|
|
|
|
//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_week_in_month = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH); |
|
|
|
|
|
|
|
//当前年的第几天 |
|
|
|
|
|
|
|
int day_of_year = cal.get(Calendar.DAY_OF_YEAR); |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
//循环输出一年中的每一天 |
|
|
|
Calendar cal = Calendar.getInstance();//获取Calendar |
|
|
|
cal.setTime(new Date()); //设置日期 |
|
|
|
cal.set(Calendar.MONTH,0); //设置月份从1月开始 |
|
|
|
Integer year = cal.get(Calendar.YEAR); //获取设置的日期年份 |
|
|
|
for (int i = 0; i < 12; i++,cal.add(Calendar.MONTH, 0)) {//循环输出一年中的12个月,cal.add()方法设置每次增加一个月 |
|
|
|
Integer month = cal.get(Calendar.MONTH)+1; |
|
|
|
Integer day = sumdays(month, year); //计算每个月有多少天 |
|
|
|
System.out.println(year+"年"+month+"月"+"有"+day+"天"); |
|
|
|
for (int j = 0; j < day; j++,cal.add(Calendar.DATE, 1)) {//循环输出一个月中的每一天,cal.add()方法设置每次增加一天 |
|
|
|
Integer days = cal.get(Calendar.DATE); |
|
|
|
System.out.println(days+"日"); |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
|