You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tcZz-java/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java

64 lines
1.6 KiB

4 years ago
package com.ruoyi.quartz.util;
import java.text.ParseException;
import java.util.Date;
import org.quartz.CronExpression;
/**
* cron
*
* @author ruoyi
*
*/
public class CronUtils
{
/**
* Cron
*
* @param cronExpression Cron
* @return boolean
*/
public static boolean isValid(String cronExpression)
{
return CronExpression.isValidExpression(cronExpression);
}
/**
* ,Cron
*
* @param cronExpression Cron
* @return String ,null
*/
public static String getInvalidMessage(String cronExpression)
{
try
{
new CronExpression(cronExpression);
return null;
}
catch (ParseException pe)
{
return pe.getMessage();
}
}
/**
* Cron
*
* @param cronExpression Cron
* @return Date 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());
}
}
}