1. 程式人生 > >java獲取某個月的時間區間

java獲取某個月的時間區間

/**
	 * 獲取某個月的時間區間.
	 * 引數:2018-12-20 12:20:10
	 * 返回結果:[2018-12-01,2019-01-01]
	 * @param date
	 * @return
	 */
	public static Date[] getMonthTimeInterval(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.DAY_OF_MONTH,1);
		Date first = calendar.getTime();
		calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)+1);
		Date end = calendar.getTime();
		return new Date[]{first,end};
	}