java判断开始结束时间戳是否合法

236 阅读1分钟

创建活动的,开始时间,结束时间:
对业务时间戳判断,结束时间大于当前时间,结束时间必须大于开始时间

    public static void isErrorTime(Long startTime, Long endTime) {
        if (null == startTime && null == endTime) {
            return;
        }
        if (null == startTime) {
            startTime = 0L;
        }
        long now = System.currentTimeMillis();
        if (null == endTime) {
            endTime = now;
        }
        if (endTime.longValue() > now) {
            throw new BizException(ErrorCode.PARAM_ERROR.getCode(), "结束时间必须大于于当前时间");
        }
        if (endTime.longValue() < startTime.longValue()) {
            throw new BizException(ErrorCode.PARAM_ERROR.getCode(), "结束时间必须大于开始时间");
        }

    }