Browse Source

任务来源:机场

任务描述:集成xxl-job
develop
wubin 1 year ago
parent
commit
81e53923c8
1 changed files with 0 additions and 61 deletions
  1. +0
    -61
      tuoheng-admin/src/main/java/com/tuoheng/admin/utils/CronUtils.java

+ 0
- 61
tuoheng-admin/src/main/java/com/tuoheng/admin/utils/CronUtils.java View File

@@ -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;
}


}


Loading…
Cancel
Save