当前位置:网站首页>根据CronSequenceGenerator计算cron表达式的时间
根据CronSequenceGenerator计算cron表达式的时间
2022-07-05 13:54:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
Spring提供了CronSequenceGenerator类以便计算cron表达式的具体时间点的next方法(Spring3.2版本)和cron是否合法的isValidExpression方法(Spring4.3版本)。
实战举例:
package construct;
import org.springframework.scheduling.support.CronSequenceGenerator;
import java.util.Date;
/**
* Created by zhangzh on 2017/1/18.
*/
public class CronSequenceGeneratorTest {
public static void main(String[] args) {
String cron = "0 */5 * * * ?"; //每个五分钟执行一次
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
Date currentTime = new Date();
System.out.println("currentTime: " + currentTime);
Date nextTimePoint = cronSequenceGenerator.next(currentTime); // currentTime为计算下次时间点的开始时间
System.out.println("nextTimePoint: " + nextTimePoint);
Date nextNextTimePoint = cronSequenceGenerator.next(nextTimePoint);
System.out.println("nextNextTimePoint: " + nextNextTimePoint);
}
}输出结果:
currentTime: Wed Jan 18 19:45:25 CST 2017
nextTimePoint: Wed Jan 18 19:50:00 CST 2017
nextNextTimePoint: Wed Jan 18 19:55:00 CST 2017看,简单吧!
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/149579.html原文链接:https://javaforall.cn
边栏推荐
- NFT value and white paper acquisition
- When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
- Self built shooting range 2022
- Those things I didn't know until I took the postgraduate entrance examination
- leetcode 10. Regular expression matching regular expression matching (difficult)
- Convolutional Neural Networks简述
- Why do I support bat to dismantle "AI research institute"
- Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
- 我为什么支持 BAT 拆掉「AI 研究院」
- 金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
猜你喜欢

About the problem and solution of 403 error in wampserver

ZABBIX monitoring

Scientific running robot pancakeswap clip robot latest detailed tutorial

Can graduate students not learn English? As long as the score of postgraduate entrance examination English or CET-6 is high!

Simple process of penetration test

The development of speech recognition app with uni app is simple and fast.

Solve the problem of invalid uni app configuration page and tabbar

深拷贝真难

When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.

zabbix 监控
随机推荐
What is information security? What is included? What is the difference with network security?
Solution to the prompt of could not close zip file during phpword use
明峰医疗冲刺科创板:年营收3.5亿元 拟募资6.24亿
2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
Idea remote debugging agent
Deep copy is hard
鸿蒙第四次培训
Zhubo Huangyu: it's really bad not to understand these gold frying skills
LeetCode_3(无重复字符的最长子串)
asp. Net read TXT file
网络安全-HSRP协议
Laravel - view (new and output views)
Basic characteristics and isolation level of transactions
Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
Solve the problem of invalid uni app configuration page and tabbar
Elfk deployment
PHP character capture notes 2020-09-14
upload (1-6)
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
我为什么支持 BAT 拆掉「AI 研究院」