/** * 判断当前日期是星期几 * * @param pTime 修要判断的时间 * @return dayForWeek 判断结果 * @Exception 发生异常 */ private int dayForWeek(String pTime) throws Exception { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.setTime(format.parse(pTime)); int dayForWeek = 0; if (c.get(Calendar.DAY_OF_WEEK) == 1) { dayForWeek = 7; } else { dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1; } return dayForWeek; } /** * @Author * @Description 比较指定日期是不是当月一号 * @Date 15:11 2018/12/16 * @Param [date] * @return java.lang.Boolean **/ private Boolean compareCurrMonthOneDay(String date){ DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar1 = Calendar.getInstance(); calendar1.set(Calendar.DAY_OF_MONTH, 1); String currMonthOneDay = format.format(calendar1.getTime()); if (currMonthOneDay.equals(date)){ return true; } return false; } /** * @Author * @Description 比较传入日期是不是当年的一月一号 * @Date 15:21 2018/12/16 * @Param [date] * @return java.lang.Boolean **/ private Boolean compareYearFirst(String date){ String currYear = DateUtils.getDateTime(new Date(), "yyyy")+"-01-01"; if (currYear.equals(date)){ return true; } return false; }
日期工具类
最新推荐文章于 2024-05-10 12:06:56 发布