java cron表达式

java cron表达式

https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm

长度7位
秒分时日月星期年

Spring定时任务

# 每月的最后1天
@Scheduled(cron = "0 0 18 28–31 * ?")
public void doAtLastDayOfMonth() {
    final Calendar calendar = Calendar.getInstance();
    if (c.get(Calendar.DATE) == c.getActualMaximum(Calendar.DATE)) {
        // do something here...
    }
}

说明:
Java(Spring)

*    *    *    *    *    *    *
-    -    -    -    -    -    -
|    |    |    |    |    |    |
|    |    |    |    |    |    + year [optional]
|    |    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)
|    |    |    |    +---------- month (1 - 12)
|    |    |    +--------------- day of month (1 - 31)
|    |    +-------------------- hour (0 - 23)
|    +------------------------- min (0 - 59)
+------------------------------ second (0 - 59)

长度6位,去掉最后的年

参考:https://www.matools.com/cron

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据