|
@@ -1,7 +1,5 @@
|
|
|
package com.jiayue.biz.util;
|
|
|
|
|
|
-import com.sun.istack.internal.NotNull;
|
|
|
-
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
/**
|
|
@@ -20,7 +18,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param dateTime 时间,单位毫秒
|
|
|
* @return 月份
|
|
|
*/
|
|
|
- public static Integer getMonth(@NotNull final Long dateTime) {
|
|
|
+ public static Integer getMonth(final Long dateTime) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTimeInMillis(dateTime);
|
|
|
return calendar.get(Calendar.MONTH) + 1;
|
|
@@ -35,7 +33,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param momentLength 时刻长度,单位毫秒
|
|
|
* @return 时刻
|
|
|
*/
|
|
|
- public static int getMoment(@NotNull final Long dateTime, @NotNull final Long momentLength) {
|
|
|
+ public static int getMoment(final Long dateTime, final Long momentLength) {
|
|
|
return (int) ((dateTime - DateMomentUtil.getDayStartTime(dateTime)) / momentLength) + 1;
|
|
|
}
|
|
|
|
|
@@ -50,7 +48,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param momentLength 时刻长度,单位:毫秒
|
|
|
* @return 指定时间所在时刻的标记时间,单位:毫秒
|
|
|
*/
|
|
|
- public static long getMomentTime(@NotNull final Long dateTime, @NotNull final int signType, @NotNull final Long momentLength) throws Exception {
|
|
|
+ public static long getMomentTime(final Long dateTime, final int signType, final Long momentLength) throws Exception {
|
|
|
if (24 * 3600 * 1000L % momentLength != 0)
|
|
|
throw new Exception("时刻长度非法,时刻长度需要能够被一天整除");
|
|
|
int moment = DateMomentUtil.getMoment(dateTime, momentLength);// 获取指定时间所在时刻数
|
|
@@ -75,7 +73,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param momentLength 时刻长度,单位:毫秒
|
|
|
* @return 一天第一个时刻的标记时间,单位:毫秒
|
|
|
*/
|
|
|
- public static long getDayFirstMomentTime(@NotNull final Long dateTime, @NotNull final int signType, @NotNull final Long momentLength) throws Exception {
|
|
|
+ public static long getDayFirstMomentTime(final Long dateTime, final int signType, final Long momentLength) throws Exception {
|
|
|
if (24 * 3600 * 1000L % momentLength != 0)
|
|
|
throw new Exception("时刻长度非法,时刻长度需要能够被一天整除");
|
|
|
long dayStartTime = DateMomentUtil.getDayStartTime(dateTime);
|
|
@@ -98,7 +96,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param momentLength 时刻长度,单位:毫秒
|
|
|
* @return 一天第一个时刻的标记时间,单位:毫秒
|
|
|
*/
|
|
|
- public static long getDayLastMomentTime(@NotNull final Long dateTime, @NotNull final int signType, @NotNull final Long momentLength) throws Exception {
|
|
|
+ public static long getDayLastMomentTime(final Long dateTime, final int signType, final Long momentLength) throws Exception {
|
|
|
if (24 * 3600 * 1000L % momentLength != 0)
|
|
|
throw new Exception("时刻长度非法,时刻长度需要能够被一天整除");
|
|
|
Calendar date = Calendar.getInstance();
|
|
@@ -122,7 +120,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param dateTime 时间毫秒
|
|
|
* @return 0点0分的毫秒
|
|
|
*/
|
|
|
- public static long getDayStartTime(@NotNull final Long dateTime) {
|
|
|
+ public static long getDayStartTime(final Long dateTime) {
|
|
|
Calendar date = Calendar.getInstance();
|
|
|
date.setTimeInMillis(dateTime);
|
|
|
date.set(Calendar.HOUR_OF_DAY, 0);
|
|
@@ -138,7 +136,7 @@ public abstract class DateMomentUtil {
|
|
|
* @param dateTime 时间毫秒
|
|
|
* @return 23点59分59秒的毫秒
|
|
|
*/
|
|
|
- public static long getDayLastTime(@NotNull final Long dateTime) {
|
|
|
+ public static long getDayLastTime(final Long dateTime) {
|
|
|
Calendar date = Calendar.getInstance();
|
|
|
date.setTimeInMillis(dateTime);
|
|
|
date.set(Calendar.HOUR_OF_DAY, 23);
|
|
@@ -150,8 +148,9 @@ public abstract class DateMomentUtil {
|
|
|
|
|
|
/**
|
|
|
* 获取两个时间间的间隔天数(自然天)
|
|
|
+ *
|
|
|
* @param dateFrom 开始时间
|
|
|
- * @param dateTo 结束时间
|
|
|
+ * @param dateTo 结束时间
|
|
|
* @return 自然天数
|
|
|
*/
|
|
|
public static Integer getDaysBetweenTwoDate(Long dateFrom, Long dateTo) {
|
|
@@ -161,13 +160,14 @@ public abstract class DateMomentUtil {
|
|
|
/**
|
|
|
* 获取当前月第一天0点0分
|
|
|
* 如果是当月1号的0点-1点直接,则返回上个月的第一天的0点0分
|
|
|
+ *
|
|
|
* @return 0点0分的毫秒
|
|
|
*/
|
|
|
public static long getMonthFirstDayStartTime() {
|
|
|
Calendar date = Calendar.getInstance();
|
|
|
//每月1号的0-1点的时间,返回上个月的1号0点
|
|
|
- if("1".equals(date.get(Calendar.DAY_OF_MONTH)) && date.get(Calendar.HOUR_OF_DAY)<1){
|
|
|
- date.set(Calendar.MONTH,-1);
|
|
|
+ if ("1".equals(date.get(Calendar.DAY_OF_MONTH)) && date.get(Calendar.HOUR_OF_DAY) < 1) {
|
|
|
+ date.set(Calendar.MONTH, -1);
|
|
|
}
|
|
|
date.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
date.set(Calendar.HOUR_OF_DAY, 0);
|
|
@@ -180,12 +180,13 @@ public abstract class DateMomentUtil {
|
|
|
/**
|
|
|
* 获取当前时间
|
|
|
* 如果是当月1号的0点-1点直接,则返回上个月的最后一天23点59分
|
|
|
+ *
|
|
|
* @return 0点0分的毫秒
|
|
|
*/
|
|
|
public static long getMonthLastDayStartTime() {
|
|
|
Calendar date = Calendar.getInstance();
|
|
|
//每月1号的0-1点的时间,返回上个月的1号0点
|
|
|
- if("1".equals(date.get(Calendar.DAY_OF_MONTH)) && date.get(Calendar.HOUR_OF_DAY)<1){
|
|
|
+ if ("1".equals(date.get(Calendar.DAY_OF_MONTH)) && date.get(Calendar.HOUR_OF_DAY) < 1) {
|
|
|
date.set(Calendar.DAY_OF_MONTH, -1);
|
|
|
date.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
date.set(Calendar.MINUTE, 59);
|