com.taotao.boot.job.quartz.utils.CronUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of taotao-boot-starter-job-quartz Show documentation
Show all versions of taotao-boot-starter-job-quartz Show documentation
taotao-boot-starter-job-quartz
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.taotao.boot.job.quartz.utils;
import org.quartz.CronExpression;
import java.text.ParseException;
import java.util.Date;
/** cron 工具类 */
public class CronUtils {
/** 验证Cron表达式是否有效 */
public static boolean isValid(String cronExpression) {
return CronExpression.isValidExpression(cronExpression);
}
/** 根据给定的Cron表达式,返回下一个执行时间 */
public static Date getNextExecution(String cronExpression) {
try {
CronExpression cron = new CronExpression(cronExpression);
return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
} catch (ParseException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy