java date转换成cron表达式,如何将cron表达式转换为日期或时间

I am trying to convert the cron expression to date.

for example this is 0 0 23 1 1-12 ? expression. I want to convert to corresponding date.

How do I achieve this?

This is what I tried but it just give the description, Human readable but I want to achieve proper date format.

import java.text.ParseException;

import java.util.Date;

import org.quartz.CronExpression;

public class CRON {

public static void main(String args[]) throws ParseException

{

//AutoRegistrationJobDao obj=new AutoRegistrationJobDao();

//obj.updateLastAutoRegSchdl();

String cron ="0 0 23 1 1-12 ?";

System.out.println("cron :"+cron);

CronExpression cronExpression =new CronExpression("0 0 23 1 1-12 ?");

System.out.println(cronExpression.getExpressionSummary());

System.out.println(cronExpression.getFinalFireTime());

//System.out.println(cronExpression.getNextValidTimeAfter(date));

try {

CronExpression c =new CronExpression(cron);

Date date=c.getFinalFireTime();

System.out.println(date);

System.out.println(c.getFinalFireTime());

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

This is what I tried, I am using multiple method and using different class, but no luck

Output:

seconds: 0

minutes: 0

hours: 23

daysOfMonth: 1

months: 1,2,3,4,5,6,7,8,9,10,11,12

daysOfWeek: ?

lastdayOfWeek: false

nearestWeekday: false

NthDayOfWeek: 0

lastdayOfMonth: false

解决方案

*/20 * * * * command -> this will execute once in 20 min. This cannot be mapped to a single point of time.

Given a cron expression - there will be multplie instance in time when the job should get triggered. So you cannot expect a one to one mapping b/w the cron and a date instance.

If you have a date reference, you can figure out the next job trigger time or the like from the reference date.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值