提交修改
This commit is contained in:
parent
5a5d4ca3f0
commit
67f065057e
@ -49,6 +49,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
|
||||
public static String YYYY_MM_DD_HH = "yyyy-MM-dd HH";
|
||||
|
||||
|
||||
public static String YYYY_MM_DD_HH_MM_UTC = "yyyy-MM-ddTHH:mm";
|
||||
|
||||
public static String YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss.SSS";
|
||||
|
||||
@ -73,18 +73,29 @@ public class CronTriggerUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String cronExpression = "0 * * * * ?";
|
||||
String cronExpression = "0 0 0 1 * ?";
|
||||
Date nextTunTime = CronTriggerUtils.getCurrentExecTime(cronExpression);
|
||||
System.out.println(nextTunTime);
|
||||
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cronExpression);
|
||||
for (int i = 0; i < 10; i++){
|
||||
log.info("执行时间:" + df.format(nextTunTime));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log.info("执行时间:" + df.format(nextTunTime) + ",currentDate :{}", df.format(new Date()));
|
||||
Date nextTriggerTime = cronSequenceGenerator.next(nextTunTime);//lastMinute 我这里是上一分钟的date类型对象
|
||||
nextTunTime = nextTriggerTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
package com.heyu.api.schedule;
|
||||
|
||||
import com.heyu.api.data.utils.DateUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public enum TimeLevelEnums {
|
||||
years("年"),
|
||||
months("月"),
|
||||
days("日"),
|
||||
hours("小时"),
|
||||
minutes("分钟"),
|
||||
seconds("秒"),
|
||||
;
|
||||
|
||||
private String level;
|
||||
|
||||
TimeLevelEnums(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
public static TimeLevelEnums getTimeLevel(String date) {
|
||||
|
||||
if(date == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(date.endsWith(" 00:00:00")){
|
||||
return TimeLevelEnums.months;
|
||||
}else if(date.endsWith(" 00:00:00")){
|
||||
|
||||
|
||||
|
||||
return TimeLevelEnums.months;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String getDfCurrentDate(TimeLevelEnums enums){
|
||||
if(TimeLevelEnums.years.equals(enums)){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY);
|
||||
return sdf.format(new Date());
|
||||
}else if (TimeLevelEnums.months.equals(enums)){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM);
|
||||
return sdf.format(new Date());
|
||||
}else if (TimeLevelEnums.days.equals(enums)){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD);
|
||||
return sdf.format(new Date());
|
||||
}else if (TimeLevelEnums.hours.equals(enums)){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH);
|
||||
return sdf.format(new Date());
|
||||
}else if (TimeLevelEnums.minutes.equals(enums)){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM);
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS);
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user