特定日期的 Cron 表达式

编程入门 行业动态 更新时间:2024-10-23 22:24:07
本文介绍了特定日期的 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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 04:36:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/679007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   日期   Cron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!