|
|
@@ -1,61 +0,0 @@ |
|
|
|
package com.tuoheng.admin.utils; |
|
|
|
|
|
|
|
|
|
|
|
import org.quartz.CronExpression; |
|
|
|
|
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
*/ |
|
|
|
public class CronUtils { |
|
|
|
|
|
|
|
private static final SimpleDateFormat sdf = new SimpleDateFormat("ss mm HH dd MM ?"); |
|
|
|
|
|
|
|
/*** |
|
|
|
* 功能描述:日期转换cron表达式 |
|
|
|
* @param date |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static String formatDateByPattern(Date date) { |
|
|
|
String formatTimeStr = null; |
|
|
|
if (Objects.nonNull(date)) { |
|
|
|
formatTimeStr = sdf.format(date); |
|
|
|
} |
|
|
|
return formatTimeStr; |
|
|
|
} |
|
|
|
|
|
|
|
/*** |
|
|
|
* convert Date to cron, eg "0 07 10 15 1 ?" |
|
|
|
* @param date : 时间点 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static String getCron(Date date) { |
|
|
|
return formatDateByPattern(date); |
|
|
|
} |
|
|
|
|
|
|
|
public static String getSdf(String datestr) throws ParseException { |
|
|
|
|
|
|
|
|
|
|
|
// 创建日期格式化对象 |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
|
|
|
|
// 将日期字符串解析为Date对象 |
|
|
|
Date date = sdf.parse(datestr); |
|
|
|
|
|
|
|
// 创建Cron表达式生成器 |
|
|
|
CronExpression cronExpression = new CronExpression(String.valueOf(date)); |
|
|
|
|
|
|
|
// 获取生成的Cron表达式 |
|
|
|
String expression = cronExpression.getCronExpression(); |
|
|
|
|
|
|
|
return expression; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|