public class CronPattern extends Object
为了兼容Quartz表达式,同时支持6位和7位表达式,其中:
当为6位时,第一位表示秒 ,范围0~59,但是第一位不做匹配 当为7位时,最后一位表示年 ,范围1970~2099,但是第7位不做解析,也不做匹配
当定时任务运行到的时间匹配这些表达式后,任务被启动。
注意:
当isMatchSecond为 true时才会匹配秒部分
默认都是关闭的
对于每一个子表达式,同样支持以下形式:
间隔(/) > 区间(-) > 列表(,)
例如 2,3,6/3中,由于“/”优先级高,因此相当于2,3,(6/3),结果与 2,3,6等价
一些例子:
| Constructor and Description |
|---|
CronPattern(String pattern)
构造
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
match(Calendar calendar,
boolean isMatchSecond)
给定时间是否匹配定时任务表达式
|
boolean |
match(LocalDateTime dateTime,
boolean isMatchSecond)
给定时间是否匹配定时任务表达式
|
boolean |
match(long millis,
boolean isMatchSecond)
给定时间是否匹配定时任务表达式
|
boolean |
match(TimeZone timezone,
long millis,
boolean isMatchSecond)
给定时间是否匹配定时任务表达式
|
Calendar |
nextMatch(Calendar calendar)
返回匹配到的下一个时间,如果给定时间匹配,直接返回
|
Calendar |
nextMatchAfter(Calendar calendar)
返回匹配到的下一个时间
|
static CronPattern |
of(String pattern)
解析表达式为 CronPattern
|
String |
toString() |
public CronPattern(String pattern)
pattern - 表达式public static CronPattern of(String pattern)
pattern - 表达式public boolean match(long millis,
boolean isMatchSecond)
millis - 时间毫秒数isMatchSecond - 是否匹配秒true, 否则返回 falsepublic boolean match(TimeZone timezone, long millis, boolean isMatchSecond)
timezone - 时区 TimeZonemillis - 时间毫秒数isMatchSecond - 是否匹配秒true, 否则返回 falsepublic boolean match(Calendar calendar, boolean isMatchSecond)
calendar - 时间isMatchSecond - 是否匹配秒true, 否则返回 falsepublic boolean match(LocalDateTime dateTime, boolean isMatchSecond)
dateTime - 时间isMatchSecond - 是否匹配秒true, 否则返回 falsepublic Calendar nextMatchAfter(Calendar calendar)
calendar - 时间public Calendar nextMatch(Calendar calendar)
calendar - 时间Copyright © 2025. All rights reserved.