特定日期的 Cron 表达式 [英] Cron expression for particular date

查看:122
本文介绍了特定日期的 Cron 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个表示 2010 年 9 月 6 日上午 6 点的 cron 表达式

I want a cron expression that represents 6th September 2010 6:00 am

推荐答案

原始问题被标记为 cron 所以第一部分适用于此.有关 Quartz CronTrigger 工具的更新答案,请参见下文.

Original question was tagged cron so this first section applies to that. See below for an updated answer for the Quartz CronTrigger tool.

大多数 crontab 不允许您指定年份,因此您可能必须将其放入脚本本身(或脚本/程序的包装器)中.

Most crontabs don't let you specify the year so you'll probably have to put that in the script itself (or a wrapper around the script/program).

你可以这样做:

if [[ $(date +%Y) != 2010 ]] ; then
    exit
fi

您正在寻找的在每年 9 月 6 日早上 6 点运行的选项

The option you're looking for to run at 6am on September 6 every year is

0 6 6 9 * your_command_goes_here
| | | | |
| | | | +- any day of the week.
| | | +--- 9th month (September).
| | +----- 6th day of the month.
| +------- 6th hour of the day.
+--------- Top of the hour (minutes = 0).

<小时>

对于 Quartz CronTrigger 格式,您会看到如下内容:


For the Quartz CronTrigger format, you'd be looking at something like:

0 0 6 6 9 ? 2010
| | | | | |   |
| | | | | |   +- 2010 only.
| | | | | +----- any day of the week.
| | | | +------- 9th month (September).
| | | +--------- 6th day of the month.
| | +----------- 6th hour of the day.
| +------------- Top of the hour (minutes = 0).
+--------------- Top of the minute (seconds = 0).

(详细信息来自此处).

这篇关于特定日期的 Cron 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆